Skip to content

Commit

Permalink
fix benchmark and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasen committed Dec 9, 2015
1 parent b3235cf commit 2cbc5ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,22 @@ func init() {
_BackendAddrCache.Store(make(backendAddrMap))
}

func decryptBackendAddr(line []byte) ([]byte, error) {
func decryptBackendAddr(key []byte) ([]byte, error) {
// Try to check cache
m1 := _BackendAddrCache.Load().(backendAddrMap)
addr, ok := m1[string(line)]
k1 := string(key)
addr, ok := m1[k1]
if ok {
return addr, nil
}

// Try to decrypt it (AES)
addr, err := _Aes256CBC.Decrypt(_SecretPassphase, line)
addr, err := _Aes256CBC.Decrypt(_SecretPassphase, key)
if err != nil {
return nil, err
}

cacheBackendAddr(string(line), addr)
cacheBackendAddr(k1, addr)
return addr, nil
}

Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func BenchmarkEncryptText(b *testing.B) {
func BenchmarkDecryptText(b *testing.B) {
for i := 0; i < b.N; i++ {
o := aes256cbc.New()
_, err := o.Decrypt(_secret, _expectAESCiphertext)
_, err := o.DecryptString(_secret, _expectAESCiphertext)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 2cbc5ad

Please sign in to comment.