github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/kbfsmd/root_metadata_test_util.go (about)

     1  // Copyright 2016 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package kbfsmd
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/keybase/client/go/kbfs/kbfscodec"
    11  	"github.com/keybase/client/go/kbfs/kbfscrypto"
    12  	"github.com/keybase/client/go/kbfs/tlf"
    13  )
    14  
    15  // FakeInitialRekey fakes the initial rekey for the given
    16  // RootMetadata. This is necessary since newly-created
    17  // RootMetadata objects don't have enough data to build a
    18  // TlfHandle from until the first rekey. pubKey is non-empty only for
    19  // server-side tests.
    20  func FakeInitialRekey(md MutableRootMetadata,
    21  	h tlf.Handle, pubKey kbfscrypto.TLFPublicKey) ExtraMetadata {
    22  	if md.LatestKeyGeneration() >= FirstValidKeyGen {
    23  		panic(fmt.Errorf("FakeInitialRekey called on MD with existing key generations"))
    24  	}
    25  
    26  	wKeys := make(UserDevicePublicKeys)
    27  	for _, w := range h.Writers {
    28  		k := kbfscrypto.MakeFakeCryptPublicKeyOrBust(string(w))
    29  		wKeys[w.AsUserOrBust()] = DevicePublicKeys{
    30  			k: true,
    31  		}
    32  	}
    33  
    34  	rKeys := make(UserDevicePublicKeys)
    35  	for _, r := range h.Readers {
    36  		k := kbfscrypto.MakeFakeCryptPublicKeyOrBust(string(r))
    37  		rKeys[r.AsUserOrBust()] = DevicePublicKeys{
    38  			k: true,
    39  		}
    40  	}
    41  
    42  	codec := kbfscodec.NewMsgpack()
    43  	tlfCryptKey := kbfscrypto.MakeTLFCryptKey([32]byte{0x1})
    44  	extra, _, err := md.AddKeyGeneration(
    45  		codec, nil, wKeys, rKeys,
    46  		kbfscrypto.TLFEphemeralPublicKey{},
    47  		kbfscrypto.TLFEphemeralPrivateKey{},
    48  		pubKey, kbfscrypto.TLFCryptKey{}, tlfCryptKey)
    49  	if err != nil {
    50  		panic(err)
    51  	}
    52  	err = md.FinalizeRekey(codec, extra)
    53  	if err != nil {
    54  		panic(err)
    55  	}
    56  	return extra
    57  }