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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94f332ce203bbad97ad3672c32a1f4d5802a18ff
4
- data.tar.gz: 35707ee0acbba0620a5807f68cc1718378dfab44
3
+ metadata.gz: acfdde4dacfa8c79dbb8c79cc752450016d0b38a
4
+ data.tar.gz: 1ad28c3ae30992f427b1c57ee39d99684457f5d3
5
5
  SHA512:
6
- metadata.gz: a577783a6c49a53d3cad4d8b4d2db752fca3147ac6a9a9bf86a8737da0a8fa023b1f4a2142fdbcc1aeb5b97ba9b01b14f04d81f8c7485b61403e3f3fb4a608e8
7
- data.tar.gz: 439b0519801f2798ee1053bcd4b26717a84bfe67ba64d047fb9a4cdc5af7e7c33260ec07547a685938d9ceb376e178217ce7c6299dea2ba27994d59d9d77ae14
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
- decrypted
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
@@ -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
- decrypted
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
@@ -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
- decrypted
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
@@ -1,3 +1,3 @@
1
1
  module Sodium
2
- VERSION = Gem::Version.new('0.4.2')
2
+ VERSION = Gem::Version.new('0.4.3')
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-libsodium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Beskow