MCPcopy Index your code
hub / github.com/rclone/rclone / decryptSegment

Method decryptSegment

backend/crypt/cipher.go:288–312  ·  view source on GitHub ↗

decryptSegment decrypts a path segment

(ciphertext string)

Source from the content-addressed store, hash-verified

286
287// decryptSegment decrypts a path segment
288func (c *Cipher) decryptSegment(ciphertext string) (string, error) {
289 if ciphertext == "" {
290 return "", nil
291 }
292 rawCiphertext, err := c.fileNameEnc.DecodeString(ciphertext)
293 if err != nil {
294 return "", err
295 }
296 if len(rawCiphertext)%nameCipherBlockSize != 0 {
297 return "", ErrorNotAMultipleOfBlocksize
298 }
299 if len(rawCiphertext) == 0 {
300 // not possible if decodeFilename() working correctly
301 return "", ErrorTooShortAfterDecode
302 }
303 if len(rawCiphertext) > 2048 {
304 return "", ErrorTooLongAfterDecode
305 }
306 paddedPlaintext := eme.Transform(c.block, c.nameTweak[:], rawCiphertext, eme.DirectionDecrypt)
307 plaintext, err := pkcs7.Unpad(nameCipherBlockSize, paddedPlaintext)
308 if err != nil {
309 return "", err
310 }
311 return string(plaintext), err
312}
313
314// Simple obfuscation routines
315func (c *Cipher) obfuscateSegment(plaintext string) string {

Callers 5

decryptFileNameMethod · 0.95
testEncryptSegmentFunction · 0.80
TestDecryptSegmentBase32Function · 0.80
TestDecryptSegmentBase64Function · 0.80

Calls 2

UnpadFunction · 0.92
DecodeStringMethod · 0.65

Tested by 4

testEncryptSegmentFunction · 0.64
TestDecryptSegmentBase32Function · 0.64
TestDecryptSegmentBase64Function · 0.64