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

     1  // Copyright 2017 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  )
    12  
    13  // ExtraMetadata is a per-version blob of extra metadata which may
    14  // exist outside of the given metadata block, e.g. key bundles for
    15  // post-v2 metadata.
    16  type ExtraMetadata interface {
    17  	MetadataVersion() MetadataVer
    18  	DeepCopy(kbfscodec.Codec) (ExtraMetadata, error)
    19  	MakeSuccessorCopy(kbfscodec.Codec) (ExtraMetadata, error)
    20  }
    21  
    22  // DumpExtraMetadata returns a detailed dump of the given
    23  // ExtraMetadata's contents.
    24  func DumpExtraMetadata(
    25  	codec kbfscodec.Codec, extra ExtraMetadata) (string, error) {
    26  	var s string
    27  	if extra, ok := extra.(*ExtraMetadataV3); ok {
    28  		serializedWKB, err := codec.Encode(extra.GetWriterKeyBundle())
    29  		if err != nil {
    30  			return "", err
    31  		}
    32  		serializedRKB, err := codec.Encode(extra.GetReaderKeyBundle())
    33  		if err != nil {
    34  			return "", err
    35  		}
    36  		s = fmt.Sprintf("WKB size: %d\nRKB size: %d\n",
    37  			len(serializedWKB), len(serializedRKB))
    38  	}
    39  
    40  	s += DumpConfig().Sdump(extra)
    41  	return s, nil
    42  }