tweetnacl 0.2.0 → 0.3.0

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.
@@ -0,0 +1,2 @@
1
+ module TweetNaCl
2
+ end
@@ -0,0 +1,17 @@
1
+ module TweetNaCl
2
+ class CryptoBox
3
+ attr_reader :keypair, :cipher, :message
4
+
5
+ def initialize(keypair = KeyPair.new)
6
+ @keypair = keypair
7
+ end
8
+
9
+ def close(message, nonce)
10
+ @cipher = TweetNaCl.crypto_box(message, nonce, @keypair.public_key, @keypair.secret_key)
11
+ end
12
+
13
+ def open(box, nonce)
14
+ @message = TweetNaCl.crypto_box_open(box.cipher, nonce, @keypair.public_key, @keypair.secret_key)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module TweetNaCl
2
+ class CryptoSign
3
+ attr_reader :keypair, :signed_message, :message
4
+
5
+ def initialize(keypair = KeyPair.new(TweetNaCl.crypto_sign_keypair))
6
+ @keypair = keypair
7
+ end
8
+
9
+ def sign(message)
10
+ @signed_message = TweetNaCl.crypto_sign(message, @keypair.secret_key)
11
+ end
12
+
13
+ def verify(message)
14
+ @message = TweetNaCl.crypto_sign_open(message.signed_message, @keypair.public_key)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module TweetNaCl
2
+ class KeyPair
3
+ attr_reader :public_key, :secret_key
4
+
5
+ def initialize(keypair = TweetNaCl.crypto_box_keypair)
6
+ @public_key, @secret_key = keypair
7
+ end
8
+ end
9
+ end
@@ -1,9 +1,15 @@
1
1
  require 'tweetnacl'
2
+ require 'tweetnacl/crypto_sign'
3
+ require 'tweetnacl/crypto_box'
4
+ require 'tweetnacl/key_pair'
2
5
  require 'minitest/autorun'
3
6
  require 'minitest/assertions'
7
+ require 'pp'
4
8
 
5
9
  class String
6
10
  def hd
7
11
  self.each_byte.map { |b| sprintf("%X", b) }.join
8
12
  end
9
13
  end
14
+
15
+ ValidNonce = "x" * 24
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class CryptoBoxTest < MiniTest::Test
4
+ def test_initializes_with_a_keypair_object
5
+ TweetNaCl::CryptoBox.new(Object.new)
6
+ end
7
+
8
+ def test_generate_a_keypair_object_if_none_provided
9
+ TweetNaCl::CryptoBox.new
10
+ assert :did_not_raise, "A CryptoBox object can be created without arguments"
11
+ end
12
+
13
+ def test_can_box_a_message_with_a_nonce
14
+ message = "hello world"
15
+ nonce = ValidNonce
16
+ nonce = "*" * 24
17
+
18
+ sender , receiver = TweetNaCl::KeyPair.new, TweetNaCl::KeyPair.new
19
+
20
+ encryption_keypair = TweetNaCl::KeyPair.new([receiver.public_key, sender.secret_key])
21
+ encrypted_box = TweetNaCl::CryptoBox.new(encryption_keypair)
22
+ encrypted_box.close(message, nonce)
23
+
24
+ decryption_keypair = TweetNaCl::KeyPair.new([sender.public_key, receiver.secret_key])
25
+ decryption_box = TweetNaCl::CryptoBox.new(decryption_keypair)
26
+ decryption_box.open(encrypted_box, nonce)
27
+
28
+ assert_equal message, decryption_box.message
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class CryptoSignTest < MiniTest::Test
4
+ def test_initializes_with_a_keypair_object
5
+ TweetNaCl::CryptoSign.new(Object.new)
6
+ end
7
+
8
+ def test_generate_a_keypair_object_if_none_provided
9
+ TweetNaCl::CryptoSign.new
10
+ assert :did_not_raise, "A CryptoSign object can be created without arguments"
11
+ end
12
+
13
+ def test_can_sign_a_message
14
+ message = "hello world"
15
+
16
+ sender_keypair = TweetNaCl::KeyPair.new(TweetNaCl.crypto_sign_keypair)
17
+ signed_message = TweetNaCl::CryptoSign.new(sender_keypair)
18
+ signed_message.sign(message)
19
+
20
+ verified_message = TweetNaCl::CryptoSign.new(sender_keypair)
21
+ verified_message.verify(signed_message)
22
+
23
+ assert_equal message, verified_message.message
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ module TweetNaCl
4
+ class KeyPairTest < MiniTest::Test
5
+ def test_initializes_with_a_key_pair
6
+ kp = TweetNaCl::KeyPair.new([nil,nil])
7
+ assert_respond_to kp, :public_key
8
+ assert_respond_to kp, :secret_key
9
+ end
10
+
11
+ def test_can_generate_a_keypair_if_none_provided
12
+ kp = TweetNaCl::KeyPair.new
13
+ assert kp.public_key
14
+ assert kp.secret_key
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class TweetNaClAliasTest < MiniTest::Test
4
+ def test_crypto_box_aliased_curve25519xsalsa20poly1305
5
+ assert_equal TweetNaCl.method(:crypto_box), TweetNaCl.method(:crypto_box_curve25519xsalsa20poly1305)
6
+ assert_equal TweetNaCl.method(:crypto_box_open), TweetNaCl.method(:crypto_box_curve25519xsalsa20poly1305_open)
7
+ end
8
+
9
+ def test_crypto_secretbox_aliased_xsalsa20poly1305
10
+ assert_equal TweetNaCl.method(:crypto_secretbox), TweetNaCl.method(:crypto_secretbox_xsalsa20poly1305)
11
+ assert_equal TweetNaCl.method(:crypto_secretbox_open), TweetNaCl.method(:crypto_secretbox_xsalsa20poly1305_open)
12
+ end
13
+
14
+ def test_crypto_sign_aliased_ed25519
15
+ assert_equal TweetNaCl.method(:crypto_sign), TweetNaCl.method(:crypto_sign_ed25519)
16
+ assert_equal TweetNaCl.method(:crypto_sign_open), TweetNaCl.method(:crypto_sign_ed25519_open)
17
+ end
18
+ end
@@ -0,0 +1,172 @@
1
+ require 'test_helper'
2
+
3
+ class TweetNaClConstantsTest < MiniTest::Test
4
+ def _const(const_name)
5
+ TweetNaCl.const_get(const_name)
6
+ end
7
+
8
+ def test_constants
9
+ assert_instance_of String, _const("CRYPTO_AUTH_PRIMITIVE")
10
+ assert_instance_of Fixnum, _const("CRYPTO_AUTH_BYTES")
11
+ assert_instance_of Fixnum, _const("CRYPTO_AUTH_KEYBYTES")
12
+ assert_instance_of String, _const("CRYPTO_AUTH_IMPLEMENTATION")
13
+ assert_instance_of String, _const("CRYPTO_AUTH_VERSION")
14
+ assert_instance_of Fixnum, _const("CRYPTO_AUTH_HMACSHA512256_TWEET_BYTES")
15
+ assert_instance_of Fixnum, _const("CRYPTO_AUTH_HMACSHA512256_TWEET_KEYBYTES")
16
+ assert_instance_of String, _const("CRYPTO_AUTH_HMACSHA512256_TWEET_VERSION")
17
+ assert_instance_of Fixnum, _const("CRYPTO_AUTH_HMACSHA512256_BYTES")
18
+ assert_instance_of Fixnum, _const("CRYPTO_AUTH_HMACSHA512256_KEYBYTES")
19
+ assert_instance_of String, _const("CRYPTO_AUTH_HMACSHA512256_VERSION")
20
+ assert_instance_of String, _const("CRYPTO_AUTH_HMACSHA512256_IMPLEMENTATION")
21
+ assert_instance_of String, _const("CRYPTO_BOX_PRIMITIVE")
22
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_PUBLICKEYBYTES")
23
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_SECRETKEYBYTES")
24
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_BEFORENMBYTES")
25
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_NONCEBYTES")
26
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_ZEROBYTES")
27
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_BOXZEROBYTES")
28
+ assert_instance_of String, _const("CRYPTO_BOX_IMPLEMENTATION")
29
+ assert_instance_of String, _const("CRYPTO_BOX_VERSION")
30
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_TWEET_PUBLICKEYBYTES")
31
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_TWEET_SECRETKEYBYTES")
32
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_TWEET_BEFORENMBYTES")
33
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_TWEET_NONCEBYTES")
34
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_TWEET_ZEROBYTES")
35
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_TWEET_BOXZEROBYTES")
36
+ assert_instance_of String, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_TWEET_VERSION")
37
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_PUBLICKEYBYTES")
38
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_SECRETKEYBYTES")
39
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BEFORENMBYTES")
40
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_NONCEBYTES")
41
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES")
42
+ assert_instance_of Fixnum, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES")
43
+ assert_instance_of String, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_VERSION")
44
+ assert_instance_of String, _const("CRYPTO_BOX_CURVE25519XSALSA20POLY1305_IMPLEMENTATION")
45
+ assert_instance_of String, _const("CRYPTO_CORE_PRIMITIVE")
46
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_OUTPUTBYTES")
47
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_INPUTBYTES")
48
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_KEYBYTES")
49
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_CONSTBYTES")
50
+ assert_instance_of String, _const("CRYPTO_CORE_IMPLEMENTATION")
51
+ assert_instance_of String, _const("CRYPTO_CORE_VERSION")
52
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_SALSA20_TWEET_OUTPUTBYTES")
53
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_SALSA20_TWEET_INPUTBYTES")
54
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_SALSA20_TWEET_KEYBYTES")
55
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_SALSA20_TWEET_CONSTBYTES")
56
+ assert_instance_of String, _const("CRYPTO_CORE_SALSA20_TWEET_VERSION")
57
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_SALSA20_OUTPUTBYTES")
58
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_SALSA20_INPUTBYTES")
59
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_SALSA20_KEYBYTES")
60
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_SALSA20_CONSTBYTES")
61
+ assert_instance_of String, _const("CRYPTO_CORE_SALSA20_VERSION")
62
+ assert_instance_of String, _const("CRYPTO_CORE_SALSA20_IMPLEMENTATION")
63
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_HSALSA20_TWEET_OUTPUTBYTES")
64
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_HSALSA20_TWEET_INPUTBYTES")
65
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_HSALSA20_TWEET_KEYBYTES")
66
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_HSALSA20_TWEET_CONSTBYTES")
67
+ assert_instance_of String, _const("CRYPTO_CORE_HSALSA20_TWEET_VERSION")
68
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_HSALSA20_OUTPUTBYTES")
69
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_HSALSA20_INPUTBYTES")
70
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_HSALSA20_KEYBYTES")
71
+ assert_instance_of Fixnum, _const("CRYPTO_CORE_HSALSA20_CONSTBYTES")
72
+ assert_instance_of String, _const("CRYPTO_CORE_HSALSA20_VERSION")
73
+ assert_instance_of String, _const("CRYPTO_CORE_HSALSA20_IMPLEMENTATION")
74
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_PRIMITIVE")
75
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_STATEBYTES")
76
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_BLOCKBYTES")
77
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_IMPLEMENTATION")
78
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_VERSION")
79
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_SHA512_TWEET_STATEBYTES")
80
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_SHA512_TWEET_BLOCKBYTES")
81
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_SHA512_TWEET_VERSION")
82
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_SHA512_STATEBYTES")
83
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_SHA512_BLOCKBYTES")
84
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_SHA512_VERSION")
85
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_SHA512_IMPLEMENTATION")
86
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_SHA256_TWEET_STATEBYTES")
87
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_SHA256_TWEET_BLOCKBYTES")
88
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_SHA256_TWEET_VERSION")
89
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_SHA256_STATEBYTES")
90
+ assert_instance_of Fixnum, _const("CRYPTO_HASHBLOCKS_SHA256_BLOCKBYTES")
91
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_SHA256_VERSION")
92
+ assert_instance_of String, _const("CRYPTO_HASHBLOCKS_SHA256_IMPLEMENTATION")
93
+ assert_instance_of String, _const("CRYPTO_HASH_PRIMITIVE")
94
+ assert_instance_of Fixnum, _const("CRYPTO_HASH_BYTES")
95
+ assert_instance_of String, _const("CRYPTO_HASH_IMPLEMENTATION")
96
+ assert_instance_of String, _const("CRYPTO_HASH_VERSION")
97
+ assert_instance_of Fixnum, _const("CRYPTO_HASH_SHA512_TWEET_BYTES")
98
+ assert_instance_of String, _const("CRYPTO_HASH_SHA512_TWEET_VERSION")
99
+ assert_instance_of Fixnum, _const("CRYPTO_HASH_SHA512_BYTES")
100
+ assert_instance_of String, _const("CRYPTO_HASH_SHA512_VERSION")
101
+ assert_instance_of String, _const("CRYPTO_HASH_SHA512_IMPLEMENTATION")
102
+ assert_instance_of Fixnum, _const("CRYPTO_HASH_SHA256_TWEET_BYTES")
103
+ assert_instance_of String, _const("CRYPTO_HASH_SHA256_TWEET_VERSION")
104
+ assert_instance_of Fixnum, _const("CRYPTO_HASH_SHA256_BYTES")
105
+ assert_instance_of String, _const("CRYPTO_HASH_SHA256_VERSION")
106
+ assert_instance_of String, _const("CRYPTO_HASH_SHA256_IMPLEMENTATION")
107
+ assert_instance_of String, _const("CRYPTO_ONETIMEAUTH_PRIMITIVE")
108
+ assert_instance_of Fixnum, _const("CRYPTO_ONETIMEAUTH_BYTES")
109
+ assert_instance_of Fixnum, _const("CRYPTO_ONETIMEAUTH_KEYBYTES")
110
+ assert_instance_of String, _const("CRYPTO_ONETIMEAUTH_IMPLEMENTATION")
111
+ assert_instance_of String, _const("CRYPTO_ONETIMEAUTH_VERSION")
112
+ assert_instance_of Fixnum, _const("CRYPTO_ONETIMEAUTH_POLY1305_TWEET_BYTES")
113
+ assert_instance_of Fixnum, _const("CRYPTO_ONETIMEAUTH_POLY1305_TWEET_KEYBYTES")
114
+ assert_instance_of String, _const("CRYPTO_ONETIMEAUTH_POLY1305_TWEET_VERSION")
115
+ assert_instance_of Fixnum, _const("CRYPTO_ONETIMEAUTH_POLY1305_BYTES")
116
+ assert_instance_of Fixnum, _const("CRYPTO_ONETIMEAUTH_POLY1305_KEYBYTES")
117
+ assert_instance_of String, _const("CRYPTO_ONETIMEAUTH_POLY1305_VERSION")
118
+ assert_instance_of String, _const("CRYPTO_ONETIMEAUTH_POLY1305_IMPLEMENTATION")
119
+ assert_instance_of String, _const("CRYPTO_SCALARMULT_PRIMITIVE")
120
+ assert_instance_of Fixnum, _const("CRYPTO_SCALARMULT_BYTES")
121
+ assert_instance_of Fixnum, _const("CRYPTO_SCALARMULT_SCALARBYTES")
122
+ assert_instance_of String, _const("CRYPTO_SCALARMULT_IMPLEMENTATION")
123
+ assert_instance_of String, _const("CRYPTO_SCALARMULT_VERSION")
124
+ assert_instance_of Fixnum, _const("CRYPTO_SCALARMULT_CURVE25519_TWEET_BYTES")
125
+ assert_instance_of Fixnum, _const("CRYPTO_SCALARMULT_CURVE25519_TWEET_SCALARBYTES")
126
+ assert_instance_of String, _const("CRYPTO_SCALARMULT_CURVE25519_TWEET_VERSION")
127
+ assert_instance_of Fixnum, _const("CRYPTO_SCALARMULT_CURVE25519_BYTES")
128
+ assert_instance_of Fixnum, _const("CRYPTO_SCALARMULT_CURVE25519_SCALARBYTES")
129
+ assert_instance_of String, _const("CRYPTO_SCALARMULT_CURVE25519_VERSION")
130
+ assert_instance_of String, _const("CRYPTO_SCALARMULT_CURVE25519_IMPLEMENTATION")
131
+ assert_instance_of String, _const("CRYPTO_SECRETBOX_PRIMITIVE")
132
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_KEYBYTES")
133
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_NONCEBYTES")
134
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_ZEROBYTES")
135
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_BOXZEROBYTES")
136
+ assert_instance_of String, _const("CRYPTO_SECRETBOX_IMPLEMENTATION")
137
+ assert_instance_of String, _const("CRYPTO_SECRETBOX_VERSION")
138
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_TWEET_KEYBYTES")
139
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_TWEET_NONCEBYTES")
140
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_TWEET_ZEROBYTES")
141
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_TWEET_BOXZEROBYTES")
142
+ assert_instance_of String, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_TWEET_VERSION")
143
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_KEYBYTES")
144
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_NONCEBYTES")
145
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_ZEROBYTES")
146
+ assert_instance_of Fixnum, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_BOXZEROBYTES")
147
+ assert_instance_of String, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_VERSION")
148
+ assert_instance_of String, _const("CRYPTO_SECRETBOX_XSALSA20POLY1305_IMPLEMENTATION")
149
+ assert_instance_of String, _const("CRYPTO_SIGN_PRIMITIVE")
150
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_BYTES")
151
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_PUBLICKEYBYTES")
152
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_SECRETKEYBYTES")
153
+ assert_instance_of String, _const("CRYPTO_SIGN_IMPLEMENTATION")
154
+ assert_instance_of String, _const("CRYPTO_SIGN_VERSION")
155
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_ED25519_TWEET_BYTES")
156
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_ED25519_TWEET_PUBLICKEYBYTES")
157
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_ED25519_TWEET_SECRETKEYBYTES")
158
+ assert_instance_of String, _const("CRYPTO_SIGN_ED25519_TWEET_VERSION")
159
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_ED25519_BYTES")
160
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_ED25519_PUBLICKEYBYTES")
161
+ assert_instance_of Fixnum, _const("CRYPTO_SIGN_ED25519_SECRETKEYBYTES")
162
+ assert_instance_of String, _const("CRYPTO_SIGN_ED25519_VERSION")
163
+ assert_instance_of String, _const("CRYPTO_SIGN_ED25519_IMPLEMENTATION")
164
+ assert_instance_of String, _const("CRYPTO_STREAM_PRIMITIVE")
165
+ assert_instance_of Fixnum, _const("CRYPTO_STREAM_KEYBYTES")
166
+ assert_instance_of Fixnum, _const("CRYPTO_STREAM_NONCEBYTES")
167
+ assert_instance_of String, _const("CRYPTO_STREAM_IMPLEMENTATION")
168
+ assert_instance_of String, _const("CRYPTO_STREAM_VERSION")
169
+ assert_instance_of Fixnum, _const("CRYPTO_STREAM_XSALSA20_TWEET_KEYBYTES")
170
+ assert_instance_of Fixnum, _const("CRYPTO_STREAM_XSALSA20_TWEET_NONCEBYTES")
171
+ end
172
+ end
@@ -1,14 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TweetNaClCryptoBoxKeyPairTest < MiniTest::Test
4
- def setup
5
- @t = TweetNaCl.new
6
- end
7
-
8
- def teardown; end
9
-
10
4
  def test_generate_a_keypair
11
- pk, sk = @t.crypto_box_keypair
5
+ pk, sk = TweetNaCl.crypto_box_keypair
12
6
 
13
7
  assert_equal 32, pk.length
14
8
  assert_equal 32, sk.length
@@ -1,49 +1,23 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TweetNaClCryptoBoxOpenTest < MiniTest::Test
4
- def setup
5
- @t = TweetNaCl.new
4
+ def test_crypto_box_open_require_cipher_to_decrypt
5
+ assert_raises(ArgumentError) { TweetNaCl.crypto_box_open(nil, nil, nil, nil) }
6
6
  end
7
7
 
8
- def teardown; end
8
+ def test_crypto_box_open_nonce_not_correct_length
9
+ assert_raises(ArgumentError) { TweetNaCl.crypto_box("foo", "bar", "pk", "sk") }
10
+ end
9
11
 
10
- def test_crypto_box_open_require_cipher_to_decrypt
11
- set = false
12
- begin
13
- @t.crypto_box_open(nil, nil, nil, nil)
14
- rescue Exception => e
15
- set = true
16
- end
17
- assert set, "A cipher is required"
12
+ def test_crypto_box_open_require_matching_public_and_secret_keys
13
+ assert_raises(RuntimeError) { TweetNaCl.crypto_box_open("foo", "x"*24, "x"*32, "x"*32) }
18
14
  end
19
15
 
20
16
  def test_crypto_box_open_require_public_key
21
- set = false
22
- begin
23
- @t.crypto_box_open("foo", nil, "foo", nil)
24
- rescue ArgumentError => e
25
- set = true
26
- end
27
- assert set, "A public key is required"
17
+ assert_raises(ArgumentError) { TweetNaCl.crypto_box_open("foo", "x"*24, "foo", nil) }
28
18
  end
29
19
 
30
20
  def test_crypto_box_open_require_secret_key
31
- set = false
32
- begin
33
- @t.crypto_box_open("foo", "foo", "foo", nil)
34
- rescue ArgumentError => e
35
- set = true
36
- end
37
- assert set, "A secret key is required"
38
- end
39
-
40
- def test_crypto_box_open_nonce_not_correct_length
41
- set = false
42
- begin
43
- @t.crypto_box("foo", "bar", "pk", "sk")
44
- rescue ArgumentError => e
45
- set = true
46
- end
47
- assert set, "Incorrect nonce length should have raised ArgumentError"
21
+ assert_raises(ArgumentError) { TweetNaCl.crypto_box_open("foo", "x"*24, "foo", nil) }
48
22
  end
49
23
  end
@@ -1,12 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TweetNaClCryptoBoxTest < MiniTest::Test
4
- def setup
5
- @t = TweetNaCl.new
6
- end
7
-
8
- def teardown; end
9
-
10
4
  def test_crypto_box
11
5
  input = "hello world"
12
6
  nonce = "*" * 24
@@ -14,51 +8,27 @@ class TweetNaClCryptoBoxTest < MiniTest::Test
14
8
  pk = "\x60\xF0\x23\x07\xDF\xB6\x8B\xBB\x15\xE2\x92\x59\x05\x1B\x2D\xF8\xC8\x59\xDB\x5B\xDE\x97\xFA\xE8\x9B\x5F\xE5\x62\x63\x11\xD6\x56"
15
9
  sk = "\xBE\x38\x7C\x59\xD1\x81\x0B\xCC\x8E\xD8\x90\xDB\x3D\xF9\x80\x63\x9E\xD2\x54\x44\xFB\x4D\xD1\x92\xB6\xC6\x75\x53\xF9\x76\x9F\xCF"
16
10
 
17
- cipher = @t.crypto_box(input, nonce, pk, sk)
11
+ cipher = TweetNaCl.crypto_box(input, nonce, pk, sk)
18
12
 
19
- output = @t.crypto_box_open(cipher, nonce, pk, sk)
13
+ output = TweetNaCl.crypto_box_open(cipher, nonce, pk, sk)
20
14
 
21
15
  assert_equal input, output
22
16
  assert_equal expected_cipher, cipher.hd
23
17
  end
24
18
 
25
19
  def test_crypto_box_require_message_to_cipher
26
- set = false
27
- begin
28
- @t.crypto_box(nil, "bar", "pk", "sk")
29
- rescue ArgumentError => e
30
- set = true
31
- end
32
- assert set, "A message is required"
20
+ assert_raises(ArgumentError) { TweetNaCl.crypto_box(nil, "bar", "pk", "sk") }
33
21
  end
34
22
 
35
23
  def test_crypto_box_require_public_key
36
- set = false
37
- begin
38
- @t.crypto_box("foo", "bar", nil, "sk")
39
- rescue ArgumentError => e
40
- set = true
41
- end
42
- assert set, "A public key is required"
24
+ assert_raises(ArgumentError) { TweetNaCl.crypto_box("foo", "bar", nil, "sk") }
43
25
  end
44
26
 
45
27
  def test_crypto_box_require_secret_key
46
- set = false
47
- begin
48
- @t.crypto_box("foo", "bar", "pk", nil)
49
- rescue ArgumentError => e
50
- set = true
51
- end
52
- assert set, "A secret key is required"
28
+ assert_raises(ArgumentError) { TweetNaCl.crypto_box("foo", "bar", "pk", nil) }
53
29
  end
54
30
 
55
31
  def test_crypto_box_nonce_not_correct_length
56
- set = false
57
- begin
58
- @t.crypto_box("foo", "bar", "pk", "sk")
59
- rescue ArgumentError => e
60
- set = true
61
- end
62
- assert set, "Incorrect nonce length should have raised ArgumentError"
32
+ assert_raises(ArgumentError) { TweetNaCl.crypto_box("foo", "bar", "pk", "sk") }
63
33
  end
64
34
  end