self_crypto 0.0.2 → 0.0.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
  SHA256:
3
- metadata.gz: cd813c17a394c17cdace467370ee2347c24e79792c93a9741e45ba64782df3d7
4
- data.tar.gz: 431bf925fcbc3e70b1be2205502d7ea118dd355755379a3169a5d5244579894a
3
+ metadata.gz: c80522a003146eb903859a9fc2007546dc76ff94e599b3eaceccbe328b753fbb
4
+ data.tar.gz: a1a7eb743ed6b4c22d0a9b70c33f9aba491d6bf88a02bba32dbbb4659c570621
5
5
  SHA512:
6
- metadata.gz: 8059470ea5a266b47c68ac7a5264e4c0692b53d5a772c71dbb7f6c2bdb0cb9b51d0f9c332fc695bb543f9823363406374fc23b222f2979141662df7e755d38b4
7
- data.tar.gz: 0e7f4d7e773d0259b88675dc14852b606c864cc6f93b599d5661986879de1d88a277c54cbda6f6e8bc51b3d4354116c6ffc1ef9ad0c08dc1e386eff6ba8c050d
6
+ metadata.gz: c8bf46420a38dda34c0574ecbc9ee785290dd2d3bcd94db3513547e65fe750c9cec0c835da24043224fb3d08bb318b47263e5753ff43d6ab55569cafd8ae4f3b
7
+ data.tar.gz: 785ee198c7345c1fa6ead3df9211181de418045cc33979c414b2f150d73f43b8303edc0be6469179c3f03e4acbe262d33834be3fcec5ba371fee41fada314ef7
@@ -46,24 +46,17 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
46
46
  }
47
47
 
48
48
  if(pickle != Qnil){
49
-
50
49
  if(olm_unpickle_account(this, RSTRING_PTR(password), RSTRING_LEN(password), RSTRING_PTR(dup_string(pickle)), RSTRING_LEN(pickle)) == olm_error()){
51
-
52
50
  raise_olm_error(olm_account_last_error(this));
53
51
  }
54
- }
55
- if(seed != Qnil){
52
+ } else if(seed != Qnil){
56
53
  if(olm_create_account_derrived_keys(this, RSTRING_PTR(seed), RSTRING_LEN(seed)) == olm_error()){
57
-
58
54
  raise_olm_error(olm_account_last_error(this));
59
55
  }
60
- }
61
- else{
62
-
56
+ } else {
63
57
  size = olm_create_account_random_length(this);
64
58
 
65
59
  if(olm_create_account(this, RSTRING_PTR(get_random(size)), size) == olm_error()){
66
-
67
60
  raise_olm_error(olm_account_last_error(this));
68
61
  }
69
62
  }
@@ -48,7 +48,7 @@ static VALUE add_participant(VALUE self, VALUE identity, VALUE session)
48
48
  return identity;
49
49
  }
50
50
 
51
- static VALUE encrypt(VALUE self, VALUE plaintext)
51
+ static VALUE group_encrypt(VALUE self, VALUE plaintext)
52
52
  {
53
53
  GroupSession *this;
54
54
  VALUE ciphertext;
@@ -91,7 +91,7 @@ static VALUE encrypt(VALUE self, VALUE plaintext)
91
91
  return ciphertext;
92
92
  }
93
93
 
94
- static VALUE decrypt(VALUE self, VALUE sender, VALUE ciphertext)
94
+ static VALUE group_decrypt(VALUE self, VALUE sender, VALUE ciphertext)
95
95
  {
96
96
  GroupSession *this;
97
97
  VALUE plaintext;
@@ -165,6 +165,6 @@ void group_session_init()
165
165
 
166
166
  rb_define_method(cGroupSession, "initialize", initialize, -1);
167
167
  rb_define_method(cGroupSession, "add_participant", add_participant, 2);
168
- rb_define_method(cGroupSession, "encrypt", encrypt, 1);
169
- rb_define_method(cGroupSession, "decrypt", decrypt, 2);
168
+ rb_define_method(cGroupSession, "encrypt", group_encrypt, 1);
169
+ rb_define_method(cGroupSession, "decrypt", group_decrypt, 2);
170
170
  }
@@ -205,7 +205,7 @@ static VALUE message_type(VALUE self)
205
205
  return retval;
206
206
  }
207
207
 
208
- static VALUE encrypt(VALUE self, VALUE plain)
208
+ static VALUE session_encrypt(VALUE self, VALUE plain)
209
209
  {
210
210
  size_t cipher_size, random_size;
211
211
  void *ptr;
@@ -238,7 +238,7 @@ static VALUE encrypt(VALUE self, VALUE plain)
238
238
  return retval;
239
239
  }
240
240
 
241
- static VALUE decrypt(VALUE self, VALUE cipher)
241
+ static VALUE session_decrypt(VALUE self, VALUE cipher)
242
242
  {
243
243
  size_t plain_size, plain_max, type;
244
244
  void *ptr;
@@ -356,8 +356,8 @@ void session_init(void)
356
356
  rb_define_method(cSession, "id", get_session_id, 0);
357
357
  rb_define_method(cSession, "last_error", last_error, 0);
358
358
  rb_define_method(cSession, "has_received_message", has_received_message, 0);
359
- rb_define_method(cSession, "encrypt", encrypt, 1);
360
- rb_define_method(cSession, "decrypt", decrypt, 1);
359
+ rb_define_method(cSession, "encrypt", session_encrypt, 1);
360
+ rb_define_method(cSession, "decrypt", session_decrypt, 1);
361
361
  rb_define_method(cSession, "to_pickle", to_pickle, -1);
362
362
  rb_define_method(cSession, "will_receive?", will_receive, -1);
363
363
  }
@@ -48,12 +48,12 @@ static VALUE ed25519_pk_to_curve25519(VALUE self, VALUE ed25519_pk)
48
48
  NULL,
49
49
  &dec_sz,
50
50
  NULL,
51
- sodium_base64_VARIANT_ORIGINAL_NO_PADDING
51
+ sodium_base64_VARIANT_URLSAFE_NO_PADDING
52
52
  );
53
53
 
54
54
  if(success != 0) {
55
55
  free(dec_ptr);
56
- rb_raise(rb_eTypeError, "could not convert ed25519 public key");
56
+ rb_raise(rb_eTypeError, "could not decode ed25519 public key");
57
57
  }
58
58
 
59
59
  if((pk_ptr = malloc(pk_sz)) == NULL){
@@ -88,7 +88,7 @@ static VALUE ed25519_pk_to_curve25519(VALUE self, VALUE ed25519_pk)
88
88
 
89
89
  free(pk_ptr);
90
90
 
91
- curve25519_sk = rb_str_new(enc_ptr, enc_sz);
91
+ curve25519_sk = rb_str_new_cstr(enc_ptr);
92
92
 
93
93
  free(enc_ptr);
94
94
 
@@ -1,5 +1,5 @@
1
1
  module SelfCrypto
2
2
 
3
- VERSION="0.0.2"
3
+ VERSION="0.0.7"
4
4
 
5
5
  end
@@ -95,6 +95,16 @@ describe "Account" do
95
95
 
96
96
  end
97
97
 
98
+ describe "#inbound_session from pickled account" do
99
+
100
+ let(:remote_session){ remote.outbound_session(account.ik['curve25519'], account.otk['curve25519'].values.first) }
101
+ let(:remote_message){ remote_session.encrypt("hello") }
102
+ let(:pickled_account){ account.to_pickle("test") }
103
+ let(:unpickled_account){ SelfCrypto::Account.from_pickle(pickled_account, "test") }
104
+ it("creates session") { _(unpickled_account.inbound_session(remote_message, remote.ik['curve25519'])).must_be_kind_of SelfCrypto::Session }
105
+
106
+ end
107
+
98
108
  end
99
109
 
100
110
  end
@@ -0,0 +1,17 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/reporters'
3
+ require 'self_crypto'
4
+
5
+ reporter_options = { color: true }
6
+ Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(reporter_options)]
7
+
8
+ describe "Util" do
9
+
10
+ describe "ed25519_pk_to_curve25519" do
11
+ account = SelfCrypto::Account.from_seed("pA0H92i1hsp1/egmS/tuEho5PpsAaQYrBd0Tj7bvAPI")
12
+ ed25519_pk = Base64.urlsafe_encode64(Base64.decode64(account.ik['ed25519']), padding: false)
13
+ curve25519_pk = SelfCrypto::Util.ed25519_pk_to_curve25519(ed25519_pk)
14
+ it("should convert"){ _(account.ik['curve25519']).must_equal curve25519_pk }
15
+ end
16
+
17
+ end
@@ -25,10 +25,6 @@ class TestAccount < Minitest::Test
25
25
  assert_equal OlmError::SUCCESS, @state.last_error
26
26
  end
27
27
 
28
- def test_sign
29
- assert_instance_of String, @state.sign("hello")
30
- end
31
-
32
28
  def test_mark_keys_as_published
33
29
  assert_equal @state, @state.mark_keys_as_published
34
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: self_crypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Bevan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-19 00:00:00.000000000 Z
12
+ date: 2020-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -103,6 +103,7 @@ files:
103
103
  - test/examples/test_bob_no_answer.rb
104
104
  - test/examples/test_exchange.rb
105
105
  - test/spec/test_account.rb
106
+ - test/spec/test_util.rb
106
107
  - test/unit/test_account_methods.rb
107
108
  homepage: https://github.com/aldgate-ventures/self-crypto-ruby
108
109
  licenses:
@@ -131,4 +132,5 @@ test_files:
131
132
  - test/unit/test_account_methods.rb
132
133
  - test/examples/test_exchange.rb
133
134
  - test/examples/test_bob_no_answer.rb
135
+ - test/spec/test_util.rb
134
136
  - test/spec/test_account.rb