From 2b991c9743caa5edf38fbcdadb129ca61ffa702f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 1 Nov 2016 18:43:22 +0100 Subject: Add support for unpadded base64 filenames, "-raw64" Through base64.RawURLEncoding. New command-line parameter "-raw64". --- internal/nametransform/names.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'internal/nametransform') diff --git a/internal/nametransform/names.go b/internal/nametransform/names.go index 05ae75e..9b1639f 100644 --- a/internal/nametransform/names.go +++ b/internal/nametransform/names.go @@ -17,13 +17,20 @@ type NameTransform struct { cryptoCore *cryptocore.CryptoCore longNames bool DirIVCache dirIVCache + // b64 = either base64.URLEncoding or base64.RawURLEncoding + b64 *base64.Encoding } // New returns a new NameTransform instance. -func New(c *cryptocore.CryptoCore, longNames bool) *NameTransform { +func New(c *cryptocore.CryptoCore, longNames bool, raw64 bool) *NameTransform { + b64 := base64.URLEncoding + if raw64 { + b64 = base64.RawURLEncoding + } return &NameTransform{ cryptoCore: c, longNames: longNames, + b64: b64, } } @@ -32,7 +39,7 @@ func New(c *cryptocore.CryptoCore, longNames bool) *NameTransform { // This function is exported because it allows for a very efficient readdir // implementation (read IV once, decrypt all names using this function). func (n *NameTransform) DecryptName(cipherName string, iv []byte) (string, error) { - bin, err := base64.URLEncoding.DecodeString(cipherName) + bin, err := n.b64.DecodeString(cipherName) if err != nil { return "", err } @@ -63,6 +70,6 @@ func (n *NameTransform) EncryptName(plainName string, iv []byte) (cipherName64 s bin := []byte(plainName) bin = pad16(bin) bin = eme.Transform(n.cryptoCore.BlockCipher, iv, bin, eme.DirectionEncrypt) - cipherName64 = base64.URLEncoding.EncodeToString(bin) + cipherName64 = n.b64.EncodeToString(bin) return cipherName64 } -- cgit v1.2.3