forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root_metadata_test_util.go
57 lines (50 loc) · 1.55 KB
/
root_metadata_test_util.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package kbfsmd
import (
"fmt"
"github.com/keybase/kbfs/kbfscodec"
"github.com/keybase/kbfs/kbfscrypto"
"github.com/keybase/kbfs/tlf"
)
// FakeInitialRekey fakes the initial rekey for the given
// RootMetadata. This is necessary since newly-created
// RootMetadata objects don't have enough data to build a
// TlfHandle from until the first rekey. pubKey is non-empty only for
// server-side tests.
func FakeInitialRekey(md MutableRootMetadata,
h tlf.Handle, pubKey kbfscrypto.TLFPublicKey) ExtraMetadata {
if md.LatestKeyGeneration() >= FirstValidKeyGen {
panic(fmt.Errorf("FakeInitialRekey called on MD with existing key generations"))
}
wKeys := make(UserDevicePublicKeys)
for _, w := range h.Writers {
k := kbfscrypto.MakeFakeCryptPublicKeyOrBust(string(w))
wKeys[w.AsUserOrBust()] = DevicePublicKeys{
k: true,
}
}
rKeys := make(UserDevicePublicKeys)
for _, r := range h.Readers {
k := kbfscrypto.MakeFakeCryptPublicKeyOrBust(string(r))
rKeys[r.AsUserOrBust()] = DevicePublicKeys{
k: true,
}
}
codec := kbfscodec.NewMsgpack()
tlfCryptKey := kbfscrypto.MakeTLFCryptKey([32]byte{0x1})
extra, _, err := md.AddKeyGeneration(
codec, nil, wKeys, rKeys,
kbfscrypto.TLFEphemeralPublicKey{},
kbfscrypto.TLFEphemeralPrivateKey{},
pubKey, kbfscrypto.TLFCryptKey{}, tlfCryptKey)
if err != nil {
panic(err)
}
err = md.FinalizeRekey(codec, extra)
if err != nil {
panic(err)
}
return extra
}