github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libkey/test/empty_kmd.go (about)

     1  // Copyright 2019 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 test
     6  
     7  import (
     8  	"context"
     9  
    10  	"github.com/keybase/client/go/kbfs/idutil"
    11  	"github.com/keybase/client/go/kbfs/kbfscodec"
    12  	"github.com/keybase/client/go/kbfs/kbfscrypto"
    13  	"github.com/keybase/client/go/kbfs/kbfsmd"
    14  	"github.com/keybase/client/go/kbfs/libkey"
    15  	"github.com/keybase/client/go/kbfs/tlf"
    16  	"github.com/keybase/client/go/kbfs/tlfhandle"
    17  	"github.com/keybase/client/go/protocol/keybase1"
    18  )
    19  
    20  // EmptyKeyMetadata stores only the TLF ID and KeyGen, and no-ops the
    21  // other methods of the `libkey.KeyMetadata` interface.  This is
    22  // useful for testing.
    23  type EmptyKeyMetadata struct {
    24  	tlfID  tlf.ID
    25  	keyGen kbfsmd.KeyGen
    26  }
    27  
    28  var _ libkey.KeyMetadata = EmptyKeyMetadata{}
    29  
    30  // NewEmptyKeyMetadata creates a new `EmptyKeyMetadata` instance.
    31  func NewEmptyKeyMetadata(tlfID tlf.ID, keyGen kbfsmd.KeyGen) EmptyKeyMetadata {
    32  	return EmptyKeyMetadata{tlfID, keyGen}
    33  }
    34  
    35  // TlfID implements the `libkey.KeyMetadata` interface for EmptyKeyMetadata.
    36  func (kmd EmptyKeyMetadata) TlfID() tlf.ID {
    37  	return kmd.tlfID
    38  }
    39  
    40  // TypeForKeying implements the `libkey.KeyMetadata` interface for
    41  // EmptyKeyMetadata.
    42  func (kmd EmptyKeyMetadata) TypeForKeying() tlf.KeyingType {
    43  	return kmd.TlfID().Type().ToKeyingType()
    44  }
    45  
    46  // GetTlfHandle just returns nil. This contradicts the requirements
    47  // for KeyMetadata, but EmptyKeyMetadata shouldn't be used in contexts
    48  // that actually use GetTlfHandle().
    49  func (kmd EmptyKeyMetadata) GetTlfHandle() *tlfhandle.Handle {
    50  	return nil
    51  }
    52  
    53  // IsWriter no-ops the `libkey.KeyMetadata` interface for EmptyKeyMetadata.
    54  func (kmd EmptyKeyMetadata) IsWriter(
    55  	_ context.Context, _ kbfsmd.TeamMembershipChecker, _ idutil.OfflineStatusGetter,
    56  	_ keybase1.UID, _ kbfscrypto.VerifyingKey) (bool, error) {
    57  	return false, nil
    58  }
    59  
    60  // LatestKeyGeneration implements the `libkey.KeyMetadata` interface
    61  // for EmptyKeyMetadata.
    62  func (kmd EmptyKeyMetadata) LatestKeyGeneration() kbfsmd.KeyGen {
    63  	return kmd.keyGen
    64  }
    65  
    66  // HasKeyForUser no-ops the `libkey.KeyMetadata` interface for
    67  // EmptyKeyMetadata.
    68  func (kmd EmptyKeyMetadata) HasKeyForUser(user keybase1.UID) (bool, error) {
    69  	return false, nil
    70  }
    71  
    72  // GetTLFCryptKeyParams no-ops the `libkey.KeyMetadata` interface for
    73  // EmptyKeyMetadata.
    74  func (kmd EmptyKeyMetadata) GetTLFCryptKeyParams(
    75  	keyGen kbfsmd.KeyGen, user keybase1.UID, key kbfscrypto.CryptPublicKey) (
    76  	kbfscrypto.TLFEphemeralPublicKey, kbfscrypto.EncryptedTLFCryptKeyClientHalf,
    77  	kbfscrypto.TLFCryptKeyServerHalfID, bool, error) {
    78  	return kbfscrypto.TLFEphemeralPublicKey{},
    79  		kbfscrypto.EncryptedTLFCryptKeyClientHalf{},
    80  		kbfscrypto.TLFCryptKeyServerHalfID{}, false, nil
    81  }
    82  
    83  // StoresHistoricTLFCryptKeys no-ops the `libkey.KeyMetadata`
    84  // interface for EmptyKeyMetadata.
    85  func (kmd EmptyKeyMetadata) StoresHistoricTLFCryptKeys() bool {
    86  	return false
    87  }
    88  
    89  // GetHistoricTLFCryptKey no-ops the `libkey.KeyMetadata` interface
    90  // for EmptyKeyMetadata.
    91  func (kmd EmptyKeyMetadata) GetHistoricTLFCryptKey(
    92  	codec kbfscodec.Codec, keyGen kbfsmd.KeyGen, key kbfscrypto.TLFCryptKey) (
    93  	kbfscrypto.TLFCryptKey, error) {
    94  	return kbfscrypto.TLFCryptKey{}, nil
    95  }