self_crypto 0.0.1 → 0.0.6

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: 34537603a575a2b32c468b332dd83e91ba2516c8c09984fb99d8f55910cdb680
4
- data.tar.gz: 5e3a683e167fcdb4126bed5de9282d4d4e5c694ef54158d4dacd146b8d180d8e
3
+ metadata.gz: 73eca72eccdafd451e608539b1b3ca79e344ff359f6b4665ccb400bcd8228a96
4
+ data.tar.gz: 80b460665fb84005612a6236eca92dc99c640c1750f0cce282c31ff5acdafce9
5
5
  SHA512:
6
- metadata.gz: d0133166300cd4f784af606550459c670bdc0dde4a6db1a74e70fd0dcba36baae7a1e50604d923d0f0da25b3b59378d4418f0c671dadd1eb931faff780958be4
7
- data.tar.gz: 498ad6f393d8683d9250ce56957d09d026283449a3964e3f5193a0ad1512bfce887eb67c75a99a8ded80768de075289b728328b18e494de4e15ac0d0ee248385
6
+ metadata.gz: 85eeecb3fc6132ce712648f4490513ce4ee03e833c6eeeb6ae90211158bb6d576492c931f3f67f863fdd682f99a02a89709966c5ab4dfd34ea917bf9cc803efc
7
+ data.tar.gz: 1a6bd6df98128d36ce74225fcb83c17db9e3eb19a315ad0570760a2835248ecbea876e6d4408ecfd5940290829ea2f0c24311514aa7b36e7fd5ee6cf4fc7f4b7
@@ -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
  }
@@ -30,7 +30,6 @@ static VALUE get_olm_version(VALUE self)
30
30
 
31
31
  void Init_self_crypto(void)
32
32
  {
33
- rb_require("openssl");
34
33
  rb_require("json");
35
34
  rb_require("self_crypto/olm_error");
36
35
 
@@ -51,7 +50,24 @@ void raise_olm_error(const char *error)
51
50
 
52
51
  VALUE get_random(size_t size)
53
52
  {
54
- return rb_funcall(rb_eval_string("OpenSSL::Random"), rb_intern("random_bytes"), 1, SIZET2NUM(size));
53
+ VALUE rand;
54
+ void *ptr;
55
+
56
+ if (sodium_init() == -1) {
57
+ rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
58
+ }
59
+
60
+ if ((ptr = malloc(size)) == NULL){
61
+ rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
62
+ }
63
+
64
+ randombytes_buf(ptr, size);
65
+
66
+ rand = rb_str_new(ptr, size);
67
+
68
+ free(ptr);
69
+
70
+ return rand;
55
71
  }
56
72
 
57
73
  VALUE dup_string(VALUE str)
@@ -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.1"
3
+ VERSION="0.0.6"
4
4
 
5
5
  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
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.1
4
+ version: 0.0.6
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-18 00:00:00.000000000 Z
12
+ date: 2020-10-16 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