-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.go
39 lines (31 loc) · 870 Bytes
/
message.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 simplcrypto
import "encoding/json"
// KeyTypePair and others represent the type of key used to encrypt or sign a message
const (
KeyTypePair = "simpl.key.pair"
KeyTypeSymmetric = "simpl.key.sym"
)
// ToJSON serializes a message to JSON
func (m *Message) ToJSON() ([]byte, error) {
return json.Marshal(m)
}
// MessageFromJSON deserializes a message from JSON
func MessageFromJSON(src []byte) (*Message, error) {
m := &Message{}
if err := json.Unmarshal(src, m); err != nil {
return nil, err
}
return m, nil
}
// ToJSON serializes a signature to JSON
func (s *Signature) ToJSON() ([]byte, error) {
return json.Marshal(s)
}
// SignatureFromJSON deserializes a signature from JSON
func SignatureFromJSON(src []byte) (*Signature, error) {
s := &Signature{}
if err := json.Unmarshal(src, s); err != nil {
return nil, err
}
return s, nil
}