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)
|
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 {
|
func EncodeTransfer(to string, value string) string {
|
||||||
result, err := abi_spec.EncodeTransfer(to, value)
|
result, err := abi_spec.EncodeTransfer(to, value)
|
||||||
if err != nil {
|
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.
|
// FromString parses a connection params string required for to securely connect to another Status device.
|
||||||
// This function parses a connection string generated by ToString
|
// This function parses a connection string generated by ToString
|
||||||
func (cp *ConnectionParams) FromString(s string) error {
|
func (cp *ConnectionParams) FromString(s string) error {
|
||||||
|
|
||||||
|
if len(s) < 2 {
|
||||||
|
return fmt.Errorf("connection string is invalid: '%s'", s)
|
||||||
|
}
|
||||||
|
|
||||||
if s[:2] != connectionStringID {
|
if s[:2] != connectionStringID {
|
||||||
return fmt.Errorf("connection string doesn't begin with identifier '%s'", 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
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ValidateConnectionString(cs string) error {
|
||||||
|
ccp := ConnectionParams{}
|
||||||
|
err := ccp.FromString(cs)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -4,16 +4,15 @@ package pairing
|
||||||
type EventType string
|
type EventType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
||||||
|
// both client and server
|
||||||
EventConnectionError EventType = "connection-error"
|
EventConnectionError EventType = "connection-error"
|
||||||
|
|
||||||
EventConnectionSuccess EventType = "connection-success"
|
EventConnectionSuccess EventType = "connection-success"
|
||||||
|
|
||||||
EventTransferError EventType = "transfer-error"
|
EventTransferError EventType = "transfer-error"
|
||||||
|
|
||||||
EventTransferSuccess EventType = "transfer-success"
|
EventTransferSuccess EventType = "transfer-success"
|
||||||
|
|
||||||
|
// Only receiver side
|
||||||
EventProcessSuccess EventType = "process-success"
|
EventProcessSuccess EventType = "process-success"
|
||||||
|
|
||||||
EventProcessError EventType = "process-error"
|
EventProcessError EventType = "process-error"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue