-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathdirect.go
39 lines (28 loc) · 889 Bytes
/
direct.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package jose
import (
"errors"
)
func init() {
RegisterJwa(new(Direct))
}
// Direct (pre-shared) key management algorithm implementation
type Direct struct{
}
func (alg *Direct) Name() string {
return DIR
}
func (alg *Direct) WrapNewKey(cekSizeBits int, key interface{}, header map[string]interface{}) (cek []byte, encryptedCek []byte, err error) {
if cek,ok:=key.([]byte); ok {
return cek,[]byte{},nil
}
return nil,nil,errors.New("Direct.WrapNewKey(): expected key to be '[]byte' array")
}
func (alg *Direct) Unwrap(encryptedCek []byte, key interface{}, cekSizeBits int, header map[string]interface{}) (cek []byte, err error) {
if(len(encryptedCek)!=0) {
return nil, errors.New("Direct.Unwrap(): expected empty encrypted CEK")
}
if cek,ok:=key.([]byte); ok {
return cek,nil
}
return nil,errors.New("Direct.Unwrap(): expected key to be '[]byte' array")
}