validate invocation token args

This commit is contained in:
Fabio Bozzo
2024-12-02 14:22:42 +01:00
parent 56eab758ed
commit 311b942a6d
2 changed files with 15 additions and 0 deletions

View File

@@ -169,3 +169,14 @@ func (a *Args) Clone() *Args {
}
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
}

View File

@@ -272,6 +272,10 @@ func tokenFromModel(m tokenPayloadModel) (*Token, error) {
tkn.nonce = m.Nonce
tkn.arguments = m.Args
if err := tkn.arguments.Validate(); err != nil {
return nil, fmt.Errorf("invalid arguments: %w", err)
}
tkn.proof = m.Prf
tkn.meta = m.Meta