1package azblob 2 3import ( 4 "crypto/hmac" 5 "crypto/sha256" 6 "encoding/base64" 7) 8 9// NewUserDelegationCredential creates a new UserDelegationCredential using a Storage account's name and a user delegation key from it 10func NewUserDelegationCredential(accountName string, key UserDelegationKey) UserDelegationCredential { 11 return UserDelegationCredential{ 12 accountName: accountName, 13 accountKey: key, 14 } 15} 16 17type UserDelegationCredential struct { 18 accountName string 19 accountKey UserDelegationKey 20} 21 22// AccountName returns the Storage account's name 23func (f UserDelegationCredential) AccountName() string { 24 return f.accountName 25} 26 27// ComputeHMAC 28func (f UserDelegationCredential) ComputeHMACSHA256(message string) (base64String string) { 29 bytes, _ := base64.StdEncoding.DecodeString(f.accountKey.Value) 30 h := hmac.New(sha256.New, bytes) 31 h.Write([]byte(message)) 32 return base64.StdEncoding.EncodeToString(h.Sum(nil)) 33} 34 35// Private method to return important parameters for NewSASQueryParameters 36func (f UserDelegationCredential) getUDKParams() *UserDelegationKey { 37 return &f.accountKey 38} 39