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:
Igor Sirotin 2023-02-15 17:42:12 +03:00 committed by GitHub
parent f4f6b25302
commit 4d491da8de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 8 deletions

View File

@ -1 +1 @@
0.131.4
0.131.5

View File

@ -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 {

View File

@ -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
}

View File

@ -4,16 +4,15 @@ package pairing
type EventType string
const (
// both client and server
EventConnectionError EventType = "connection-error"
EventConnectionSuccess EventType = "connection-success"
EventTransferError EventType = "transfer-error"
EventTransferSuccess EventType = "transfer-success"
// Only receiver side
EventProcessSuccess EventType = "process-success"
EventProcessError EventType = "process-error"
)