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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package record
import (
"go.mau.fi/libsignal/ecc"
"go.mau.fi/libsignal/util/optional"
)
// NewPendingPreKey will return a new pending pre key object.
func NewPendingPreKey(preKeyID *optional.Uint32, signedPreKeyID uint32,
baseKey ecc.ECPublicKeyable) *PendingPreKey {
return &PendingPreKey{
preKeyID: preKeyID,
signedPreKeyID: signedPreKeyID,
baseKey: baseKey,
}
}
// NewPendingPreKeyFromStruct will return a new pending prekey object from the
// given structure.
func NewPendingPreKeyFromStruct(preKey *PendingPreKeyStructure) (*PendingPreKey, error) {
baseKey, err := ecc.DecodePoint(preKey.BaseKey, 0)
if err != nil {
return nil, err
}
pendingPreKey := NewPendingPreKey(
preKey.PreKeyID,
preKey.SignedPreKeyID,
baseKey,
)
return pendingPreKey, nil
}
// PendingPreKeyStructure is a serializeable structure for pending
// prekeys.
type PendingPreKeyStructure struct {
PreKeyID *optional.Uint32
SignedPreKeyID uint32
BaseKey []byte
}
// PendingPreKey is a structure for pending pre keys
// for a session state.
type PendingPreKey struct {
preKeyID *optional.Uint32
signedPreKeyID uint32
baseKey ecc.ECPublicKeyable
}
// structure will return a serializeable structure of the pending prekey.
func (p *PendingPreKey) structure() *PendingPreKeyStructure {
if p != nil {
return &PendingPreKeyStructure{
PreKeyID: p.preKeyID,
SignedPreKeyID: p.signedPreKeyID,
BaseKey: p.baseKey.Serialize(),
}
}
return nil
}
|