validate invocation token args
This commit is contained in:
@@ -169,3 +169,14 @@ func (a *Args) Clone() *Args {
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate checks that all values in the Args are valid according to UCAN specs
|
||||||
|
func (a *Args) Validate() error {
|
||||||
|
for key, value := range a.Values {
|
||||||
|
if err := limits.ValidateIntegerBoundsIPLD(value); err != nil {
|
||||||
|
return fmt.Errorf("value for key %q: %w", key, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -272,6 +272,10 @@ func tokenFromModel(m tokenPayloadModel) (*Token, error) {
|
|||||||
tkn.nonce = m.Nonce
|
tkn.nonce = m.Nonce
|
||||||
|
|
||||||
tkn.arguments = m.Args
|
tkn.arguments = m.Args
|
||||||
|
if err := tkn.arguments.Validate(); err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid arguments: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
tkn.proof = m.Prf
|
tkn.proof = m.Prf
|
||||||
tkn.meta = m.Meta
|
tkn.meta = m.Meta
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user