LocalPairing minor fixes. `ValidateConnectionString` method. (#3184)
* fix(pairing): Added ConnectionParams::FromString input length check * feat: Added `IsValidConnectionString` method * Renamed IsValidConnectionString to ValidateConnectionString * Bump version
This commit is contained in:
parent
f4f6b25302
commit
4d491da8de
|
@ -1012,6 +1012,14 @@ func InputConnectionStringForBootstrapping(cs, configJSON string) string {
|
|||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
func ValidateConnectionString(cs string) string {
|
||||
err := pairing.ValidateConnectionString(cs)
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
return err.Error()
|
||||
}
|
||||
|
||||
func EncodeTransfer(to string, value string) string {
|
||||
result, err := abi_spec.EncodeTransfer(to, value)
|
||||
if err != nil {
|
||||
|
|
|
@ -75,6 +75,11 @@ func (cp *ConnectionParams) ToString() string {
|
|||
// FromString parses a connection params string required for to securely connect to another Status device.
|
||||
// This function parses a connection string generated by ToString
|
||||
func (cp *ConnectionParams) FromString(s string) error {
|
||||
|
||||
if len(s) < 2 {
|
||||
return fmt.Errorf("connection string is invalid: '%s'", s)
|
||||
}
|
||||
|
||||
if s[:2] != connectionStringID {
|
||||
return fmt.Errorf("connection string doesn't begin with identifier '%s'", connectionStringID)
|
||||
}
|
||||
|
@ -192,3 +197,9 @@ func (cp *ConnectionParams) URL() (*url.URL, error) {
|
|||
}
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func ValidateConnectionString(cs string) error {
|
||||
ccp := ConnectionParams{}
|
||||
err := ccp.FromString(cs)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -4,17 +4,16 @@ package pairing
|
|||
type EventType string
|
||||
|
||||
const (
|
||||
EventConnectionError EventType = "connection-error"
|
||||
|
||||
// both client and server
|
||||
EventConnectionError EventType = "connection-error"
|
||||
EventConnectionSuccess EventType = "connection-success"
|
||||
EventTransferError EventType = "transfer-error"
|
||||
EventTransferSuccess EventType = "transfer-success"
|
||||
|
||||
EventTransferError EventType = "transfer-error"
|
||||
|
||||
EventTransferSuccess EventType = "transfer-success"
|
||||
|
||||
// Only receiver side
|
||||
EventProcessSuccess EventType = "process-success"
|
||||
|
||||
EventProcessError EventType = "process-error"
|
||||
EventProcessError EventType = "process-error"
|
||||
)
|
||||
|
||||
// Event is a type for transfer events.
|
||||
|
|
Loading…
Reference in New Issue