storj.io/uplink@v1.13.0/private/storage/streams/splitter/common.go (about) 1 // Copyright (C) 2023 Storj Labs, Inc. 2 // See LICENSE for copying information. 3 4 package splitter 5 6 import ( 7 "storj.io/common/encryption" 8 "storj.io/common/storj" 9 "storj.io/uplink/private/metaclient" 10 ) 11 12 // TODO: move it to separate package? 13 func encryptETag(etag []byte, cipherSuite storj.CipherSuite, contentKey *storj.Key) ([]byte, error) { 14 etagKey, err := encryption.DeriveKey(contentKey, "storj-etag-v1") 15 if err != nil { 16 return nil, err 17 } 18 19 encryptedETag, err := encryption.Encrypt(etag, cipherSuite, etagKey, &storj.Nonce{}) 20 if err != nil { 21 return nil, err 22 } 23 24 return encryptedETag, nil 25 } 26 27 func nonceForPosition(position metaclient.SegmentPosition) (storj.Nonce, error) { 28 var nonce storj.Nonce 29 inc := (int64(position.PartNumber) << 32) | (int64(position.Index) + 1) 30 _, err := encryption.Increment(&nonce, inc) 31 return nonce, err 32 }