ffi-libsodium 0.4.5 → 0.4.7

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: 6b1a503f0fa3b5aa81160f0901562ad7b3eec093
4
- data.tar.gz: a1ed939f6e4109ab1c1ce234cee10a24b9afa44f
3
+ metadata.gz: 57615067a7dd57e182c94371c5630f7647ca6912
4
+ data.tar.gz: 2cf7f5a80af79725867132e1f3592e8141306c2a
5
5
  SHA512:
6
- metadata.gz: 30a79852c979c2e52ca8bd9ea0948e20f767e1b5c09e1fab6df64af08ba4dd3a1c7628d14e96f47855fb116ee7282402b48f0349bf34bc552f123b87b955cc8d
7
- data.tar.gz: ecbc879ff635b206277f1ac857db6aa47471cd6d6a562e6669504641ca2c42dd059c44efee10c1bee7bae5026142afa9692c603dbed2fe8330c1b8ce7d2eaa23
6
+ metadata.gz: 0bc7c17c8b2b3151b0a195635aa1db849ec80eda0e7d0a253d75ef5d4560fda9f0a0221d3716fe4f3c503d48dbc061f4c9137c0516776a6c2f1bc4411224d433
7
+ data.tar.gz: a2ef65043e0794f025afc0d01e16f95e6d226f1e5ba2932aee5ab07857dda5105a7f029a7c67bb09b1643a709109bb0a30fa74f9aba9c77e422c51bf35895a3b
@@ -54,24 +54,24 @@ module Crypto
54
54
  end
55
55
 
56
56
  def decrypt(ciphertext, additional_data, nonce, key, encoding = nil)
57
- if (decrypted_len = (ciphertext_len = get_size(ciphertext)) - ABYTES) < 0
57
+ if (message_len = (ciphertext_len = get_size(ciphertext)) - ABYTES) < 0
58
58
  fail Sodium::LengthError, "Ciphertext is too short", caller
59
59
  end
60
60
 
61
61
  check_length(nonce, NPUBBYTES, :Nonce)
62
62
  check_length(key, KEYBYTES, :SecretKey)
63
63
 
64
- decrypted = zeros(decrypted_len)
64
+ message = zeros(message_len)
65
65
  key.readonly if key.is_a?(Sodium::SecretBuffer)
66
- if crypto_aead_chacha20poly1305_decrypt(decrypted, nil, nil, ciphertext, ciphertext_len, additional_data, get_size(additional_data), nonce, key) == -1
66
+ if crypto_aead_chacha20poly1305_decrypt(message, nil, nil, ciphertext, ciphertext_len, additional_data, get_size(additional_data), nonce, key) == -1
67
67
  raise Sodium::CryptoError, "Message forged", caller
68
68
  end
69
69
 
70
70
  if encoding
71
- decrypted.force_encoding(encoding)
71
+ message.force_encoding(encoding)
72
72
  end
73
73
 
74
- decrypted
74
+ message
75
75
  ensure
76
76
  key.noaccess if key.is_a?(Sodium::SecretBuffer)
77
77
  end
@@ -30,14 +30,14 @@ module Crypto
30
30
  attach_function :crypto_box_keypair, [:buffer_out, :buffer_out], :int
31
31
  attach_function :crypto_box_seed_keypair, [:buffer_out, :buffer_out, :buffer_in], :int
32
32
 
33
+ attach_function :crypto_box_beforenm, [:buffer_out, :buffer_in, :buffer_in], :int
34
+
33
35
  attach_function :crypto_box_easy, [:buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int
34
36
  attach_function :crypto_box_open_easy, [:buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int
35
37
 
36
38
  attach_function :crypto_box_detached, [:buffer_out, :buffer_out, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int
37
39
  attach_function :crypto_box_open_detached, [:buffer_out, :buffer_in, :buffer_in, :ulong_long, :buffer_in, :buffer_in, :buffer_in], :int
38
40
 
39
- attach_function :crypto_box_beforenm, [:buffer_out, :buffer_in, :buffer_in], :int
40
-
41
41
  module_function
42
42
 
43
43
  def nonce
@@ -123,17 +123,17 @@ module Crypto
123
123
  check_length(public_key, PUBLICKEYBYTES, :PublicKey)
124
124
  check_length(secret_key, SECRETKEYBYTES, :SecretKey)
125
125
 
126
- decrypted = zeros(ciphertext_len - MACBYTES)
126
+ message = zeros(ciphertext_len - MACBYTES)
127
127
  secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
128
- if crypto_box_open_easy(decrypted, ciphertext, ciphertext_len, nonce, public_key, secret_key) == -1
128
+ if crypto_box_open_easy(message, ciphertext, ciphertext_len, nonce, public_key, secret_key) == -1
129
129
  raise Sodium::CryptoError, "Message forged", caller
130
130
  end
131
131
 
132
132
  if encoding
133
- decrypted.force_encoding(encoding)
133
+ message.force_encoding(encoding)
134
134
  end
135
135
 
136
- decrypted
136
+ message
137
137
  ensure
138
138
  secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
139
139
  end
@@ -202,17 +202,17 @@ module Crypto
202
202
  check_length(public_key, PUBLICKEYBYTES, :PublicKey)
203
203
  check_length(secret_key, SECRETKEYBYTES, :SecretKey)
204
204
 
205
- decrypted = zeros(ciphertext_len)
205
+ message = zeros(ciphertext_len)
206
206
  secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
207
- if crypto_box_open_detached(decrypted, ciphertext, mac, ciphertext_len, nonce, public_key, secret_key) == -1
207
+ if crypto_box_open_detached(message, ciphertext, mac, ciphertext_len, nonce, public_key, secret_key) == -1
208
208
  raise Sodium::CryptoError, "Message forged", caller
209
209
  end
210
210
 
211
211
  if encoding
212
- decrypted.force_encoding(encoding)
212
+ message.force_encoding(encoding)
213
213
  end
214
214
 
215
- decrypted
215
+ message
216
216
  ensure
217
217
  secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
218
218
  end
@@ -115,7 +115,7 @@ module Crypto
115
115
  ciphertext = zeros(message_len)
116
116
  mac = zeros(MACBYTES)
117
117
  key.readonly if key.is_a?(Sodium::SecretBuffer)
118
- crypto_secretbox_easy(ciphertext, mac, message, message_len, nonce, key)
118
+ crypto_secretbox_detached(ciphertext, mac, message, message_len, nonce, key)
119
119
 
120
120
  [ciphertext, mac]
121
121
  ensure
@@ -128,17 +128,17 @@ module Crypto
128
128
  check_length(nonce, NONCEBYTES, :Nonce)
129
129
  check_length(key, KEYBYTES, :SecretKey)
130
130
 
131
- decrypted = zeros(ciphertext_len)
131
+ message = zeros(ciphertext_len)
132
132
  key.readonly if key.is_a?(Sodium::SecretBuffer)
133
- if crypto_secretbox_open_easy(decrypted, ciphertext, mac, ciphertext_len, nonce, key) == -1
133
+ if crypto_secretbox_open_detached(message, ciphertext, mac, ciphertext_len, nonce, key) == -1
134
134
  raise Sodium::CryptoError, "Message forged", caller
135
135
  end
136
136
 
137
137
  if encoding
138
- decrypted.force_encoding(encoding)
138
+ message.force_encoding(encoding)
139
139
  end
140
140
 
141
- decrypted
141
+ message
142
142
  ensure
143
143
  key.noaccess if key.is_a?(Sodium::SecretBuffer)
144
144
  end
@@ -149,7 +149,7 @@ module Crypto
149
149
 
150
150
  mac = zeros(MACBYTES)
151
151
  key.readonly if key.is_a?(Sodium::SecretBuffer)
152
- crypto_secretbox_easy(message, message, mac, get_size(message), nonce, key)
152
+ crypto_secretbox_detached(message, mac, message, get_size(message), nonce, key)
153
153
 
154
154
  [message, mac]
155
155
  ensure
@@ -162,7 +162,7 @@ module Crypto
162
162
  check_length(key, KEYBYTES, :SecretKey)
163
163
 
164
164
  key.readonly if key.is_a?(Sodium::SecretBuffer)
165
- if crypto_secretbox_open_easy(ciphertext, ciphertext, mac, get_size(ciphertext), nonce, key) == -1
165
+ if crypto_secretbox_open_detached(ciphertext, ciphertext, mac, get_size(ciphertext), nonce, key) == -1
166
166
  raise Sodium::CryptoError, "Message forged", caller
167
167
  end
168
168
 
@@ -90,7 +90,7 @@ module Crypto
90
90
  secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
91
91
  end
92
92
 
93
- def open(sealed_message, public_key)
93
+ def open(sealed_message, public_key, encoding = nil)
94
94
  sealed_message_len = get_size(sealed_message)
95
95
  check_length(public_key, PUBLICKEYBYTES, :PublicKey)
96
96
 
@@ -100,6 +100,10 @@ module Crypto
100
100
  raise Sodium::CryptoError, "Incorrect signature", caller
101
101
  end
102
102
 
103
+ if encoding
104
+ unsealed_message.force_encoding(encoding)
105
+ end
106
+
103
107
  unsealed_message
104
108
  end
105
109
 
@@ -1,3 +1,3 @@
1
1
  module Sodium
2
- VERSION = Gem::Version.new('0.4.5')
2
+ VERSION = Gem::Version.new('0.4.7')
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-libsodium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Beskow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-30 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi