ffi-libsodium 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/crypto/aead/chacha20_poly1305.rb +6 -2
- data/lib/crypto/box.rb +6 -2
- data/lib/crypto/secret_box.rb +6 -2
- data/lib/sodium/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acfdde4dacfa8c79dbb8c79cc752450016d0b38a
|
4
|
+
data.tar.gz: 1ad28c3ae30992f427b1c57ee39d99684457f5d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1ab577ea19b1ae9b5ca0ac4225bbe5cd5192f86d5748f26e501f80d4b082061aa43add2b079956df3ca24e08b5429c58f2259f00c7bdf6206b3e33c9bddf6dd
|
7
|
+
data.tar.gz: e925c7e55392c1c321b31ec27640a05a9361f763b40a0dccd2d8f5847ca5b19d138f01b00a580c0c2ee6e6b2daa6c41ae60093f113b232e1b359e3ea5d86a471
|
@@ -53,7 +53,7 @@ module Crypto
|
|
53
53
|
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
54
54
|
end
|
55
55
|
|
56
|
-
def decrypt(ciphertext, additional_data, nonce, key)
|
56
|
+
def decrypt(ciphertext, additional_data, nonce, key, encoding = nil)
|
57
57
|
ciphertext_len = get_size(ciphertext)
|
58
58
|
if (decrypted_len = ciphertext_len - ABYTES) >= 0
|
59
59
|
check_length(nonce, NPUBBYTES, :Nonce)
|
@@ -62,7 +62,11 @@ module Crypto
|
|
62
62
|
decrypted = zeros(decrypted_len)
|
63
63
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
64
64
|
if crypto_aead_chacha20poly1305_decrypt(decrypted, nil, nil, ciphertext, ciphertext_len, additional_data, get_size(additional_data), nonce, key) == 0
|
65
|
-
|
65
|
+
if encoding
|
66
|
+
decrypted.force_encoding(encoding)
|
67
|
+
else
|
68
|
+
decrypted
|
69
|
+
end
|
66
70
|
else
|
67
71
|
raise Sodium::CryptoError, "Message forged", caller
|
68
72
|
end
|
data/lib/crypto/box.rb
CHANGED
@@ -96,7 +96,7 @@ module Crypto
|
|
96
96
|
secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
|
97
97
|
end
|
98
98
|
|
99
|
-
def open(ciphertext, nonce, public_key, secret_key)
|
99
|
+
def open(ciphertext, nonce, public_key, secret_key, encoding = nil)
|
100
100
|
ciphertext_len = get_size(ciphertext)
|
101
101
|
check_length(nonce, NONCEBYTES, :Nonce)
|
102
102
|
check_length(public_key, PUBLICKEYBYTES, :PublicKey)
|
@@ -105,7 +105,11 @@ module Crypto
|
|
105
105
|
decrypted = zeros(ciphertext_len - MACBYTES)
|
106
106
|
secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
|
107
107
|
if crypto_box_open_easy(decrypted, ciphertext, ciphertext_len, nonce, public_key, secret_key) == 0
|
108
|
-
|
108
|
+
if encoding
|
109
|
+
decrypted.force_encoding(encoding)
|
110
|
+
else
|
111
|
+
decrypted
|
112
|
+
end
|
109
113
|
else
|
110
114
|
raise Sodium::CryptoError, "Message forged", caller
|
111
115
|
end
|
data/lib/crypto/secret_box.rb
CHANGED
@@ -44,7 +44,7 @@ module Crypto
|
|
44
44
|
key.noaccess if key.is_a?(Sodium::SecretBuffer)
|
45
45
|
end
|
46
46
|
|
47
|
-
def open(ciphertext, nonce, key)
|
47
|
+
def open(ciphertext, nonce, key, encoding = nil)
|
48
48
|
ciphertext_len = get_size(ciphertext)
|
49
49
|
check_length(nonce, NONCEBYTES, :Nonce)
|
50
50
|
check_length(key, KEYBYTES, :SecretKey)
|
@@ -52,7 +52,11 @@ module Crypto
|
|
52
52
|
decrypted = zeros(ciphertext_len - MACBYTES)
|
53
53
|
key.readonly if key.is_a?(Sodium::SecretBuffer)
|
54
54
|
if crypto_secretbox_open_easy(decrypted, ciphertext, ciphertext_len, nonce, key) == 0
|
55
|
-
|
55
|
+
if encoding
|
56
|
+
decrypted.force_encoding(encoding)
|
57
|
+
else
|
58
|
+
decrypted
|
59
|
+
end
|
56
60
|
else
|
57
61
|
raise Sodium::CryptoError, "Message forged", caller
|
58
62
|
end
|
data/lib/sodium/version.rb
CHANGED