storj.io/uplink@v1.13.0/private/piecestore/hash.go (about)

     1  // Copyright (C) 2022 Storj Labs, Inc.
     2  // See LICENSE for copying information.
     3  
     4  package piecestore
     5  
     6  import (
     7  	"context"
     8  
     9  	"storj.io/common/pb"
    10  )
    11  
    12  type pieceHashAlgoKey struct{}
    13  
    14  // WithPieceHashAlgo sets the used piece hash algorithm.
    15  func WithPieceHashAlgo(ctx context.Context, hash pb.PieceHashAlgorithm) context.Context {
    16  	return context.WithValue(ctx, pieceHashAlgoKey{}, hash)
    17  }
    18  
    19  // GetPieceHashAlgo returns with the piece hash algorithm which may be overridden.
    20  func GetPieceHashAlgo(ctx context.Context) (algo pb.PieceHashAlgorithm) {
    21  	override := ctx.Value(pieceHashAlgoKey{})
    22  	if override != nil {
    23  		return override.(pb.PieceHashAlgorithm)
    24  	}
    25  	return pb.PieceHashAlgorithm_BLAKE3
    26  }