本文整理匯總了Golang中euphoria/io/heim/proto/security.Capability類的典型用法代碼示例。如果您正苦於以下問題:Golang Capability類的具體用法?Golang Capability怎麽用?Golang Capability使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Capability類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: decryptRoomKey
func decryptRoomKey(clientKey *security.ManagedKey, capability security.Capability) (
*security.ManagedKey, error) {
if clientKey.Encrypted() {
return nil, security.ErrKeyMustBeDecrypted
}
iv, err := base64.URLEncoding.DecodeString(capability.CapabilityID())
if err != nil {
return nil, err
}
roomKeyJSON := capability.EncryptedPayload()
if err := clientKey.BlockCrypt(iv, clientKey.Plaintext, roomKeyJSON, false); err != nil {
return nil, err
}
roomKey := &security.ManagedKey{
KeyType: security.AES128,
}
if err := json.Unmarshal(clientKey.Unpad(roomKeyJSON), &roomKey.Plaintext); err != nil {
return nil, err
}
return roomKey, nil
}
示例2: Save
func (cs *capabilities) Save(ctx scope.Context, account proto.Account, c security.Capability) error {
cs.Lock()
defer cs.Unlock()
if cs.capabilities == nil {
cs.capabilities = map[string]security.Capability{}
cs.accounts = map[string]proto.Account{}
}
cid := c.CapabilityID()
cs.capabilities[cid] = c
cs.accounts[cid] = account
return nil
}
示例3: Save
func (rmc *RoomManagerCapabilities) Save(
ctx scope.Context, account proto.Account, c security.Capability) error {
capRow := &Capability{
ID: c.CapabilityID(),
NonceBytes: c.Nonce(),
EncryptedPrivateData: c.EncryptedPayload(),
PublicData: c.PublicPayload(),
}
rmCapRow := &RoomManagerCapability{
Room: rmc.Room.Name,
CapabilityID: c.CapabilityID(),
Granted: time.Now(),
}
if account != nil {
capRow.AccountID = account.ID().String()
rmCapRow.AccountID = account.ID().String()
}
return rmc.Executor.Insert(capRow, rmCapRow)
}