summaryrefslogtreecommitdiff
path: root/internal/nametransform/names_core.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-06-16 19:02:47 +0200
committerJakob Unterwurzacher2016-06-16 19:02:47 +0200
commit7e92ebe16a7735b29e0fdc62d4b5d49ce0dc2b66 (patch)
treec38b46c98ec73ea6ee48b3e6ab9569f249200e81 /internal/nametransform/names_core.go
parent6c3f97399a01a2d8480b39978209099335efbf7d (diff)
Rename nametransform, contentenc source files
Let's have shorter names, and merge *_api.go into the "main" file. No code changes.
Diffstat (limited to 'internal/nametransform/names_core.go')
-rw-r--r--internal/nametransform/names_core.go65
1 files changed, 0 insertions, 65 deletions
diff --git a/internal/nametransform/names_core.go b/internal/nametransform/names_core.go
deleted file mode 100644
index 779b885..0000000
--- a/internal/nametransform/names_core.go
+++ /dev/null
@@ -1,65 +0,0 @@
-package nametransform
-
-// Filename encryption / decryption functions
-
-import (
- "crypto/aes"
- "crypto/cipher"
- "encoding/base64"
- "fmt"
-
- "github.com/rfjakob/eme"
-)
-
-// DecryptName - decrypt base64-encoded encrypted filename "cipherName"
-// The used encryption is either CBC or EME, depending on "useEME".
-//
-// 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)
- if err != nil {
- return "", err
- }
-
- if len(bin)%aes.BlockSize != 0 {
- return "", fmt.Errorf("Decoded length %d is not a multiple of the AES block size", len(bin))
- }
-
- if n.useEME {
- bin = eme.Transform(n.cryptoCore.BlockCipher, iv, bin, eme.DirectionDecrypt)
- } else {
- cbc := cipher.NewCBCDecrypter(n.cryptoCore.BlockCipher, iv)
- cbc.CryptBlocks(bin, bin)
- }
-
- bin, err = unPad16(bin)
- if err != nil {
- return "", err
- }
-
- plain := string(bin)
- return plain, err
-}
-
-// encryptName - encrypt "plainName", return base64-encoded "cipherName64"
-// The used encryption is either CBC or EME, depending on "useEME".
-//
-// This function is exported because fusefrontend needs access to the full (not hashed)
-// name if longname is used
-func (n *NameTransform) EncryptName(plainName string, iv []byte) (cipherName64 string) {
-
- bin := []byte(plainName)
- bin = pad16(bin)
-
- if n.useEME {
- bin = eme.Transform(n.cryptoCore.BlockCipher, iv, bin, eme.DirectionEncrypt)
- } else {
- cbc := cipher.NewCBCEncrypter(n.cryptoCore.BlockCipher, iv)
- cbc.CryptBlocks(bin, bin)
- }
-
- cipherName64 = base64.URLEncoding.EncodeToString(bin)
- return cipherName64
-}