[#238] session: Add container.IssuedBy method

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2022-05-04 17:49:55 +03:00 committed by LeL
parent 539ac9915e
commit 12ea1e8d74
2 changed files with 38 additions and 0 deletions

View file

@ -376,3 +376,25 @@ func (x Container) AssertAuthKey(key neofscrypto.PublicKey) bool {
return bytes.Equal(bKey, x.body.GetSessionKey())
}
// IssuedBy returns true if session token is signed
// and, therefore, owned by specified user.
//
// See also Sign.
func (x Container) IssuedBy(id user.ID) bool {
var (
tokenOwner user.ID
v2TokenOwner = x.body.GetOwnerID()
)
if v2TokenOwner == nil {
return false
}
err := tokenOwner.ReadFromV2(*v2TokenOwner)
if err != nil {
return false
}
return tokenOwner.Equals(id)
}