tanker-core 2.4.0.alpha.9 → 2.4.1.alpha.1

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: 92eb192362e683db868e217ba8d09e0459d53c07510004d62912ad938b6b6fe5
4
- data.tar.gz: 53f4fcbf35bdfd79856a0100c1abe0365e25c9105a7026807bde9eeb6b4a3104
3
+ metadata.gz: 6ec342fffdeb5faac6b5bc784d7f82f8c311b2ca9e1faf55f831586e5675bf52
4
+ data.tar.gz: 40ec73b66868071510d2214d6f180a24b09f070ab8d9021145a8d3113bba6714
5
5
  SHA512:
6
- metadata.gz: 43ace1a65ed037af80b04cedbc40e525e4ef969a2c3b17573241d434a8678e7fa18847392762416cb9092bd0520ee4d42c8b9776a2679f07a79ec15a5d11bf6a
7
- data.tar.gz: 62edb1bb369f852b4ad7e72deb212a1bf4530b98b3c1951013c60554023b69a0caed06885581f300f824516a75ef2822cdade99ef1d5bf0bdcda444763d8fe65
6
+ metadata.gz: 2067b7f162039243d78d7a9f6a5db65c28ff270a589ead52f8a4e251ba38a080250f97fc899f5e046ce1957883395e3f39fbabdc2792020541e151ea43514598
7
+ data.tar.gz: da876bb3d3c23edbf4d6b6d09f74c95e9d73c98cb3e9cb63a70e19df6e33329be83b478abf11203694e10584db79467b864078dd7ed35ecce7ed5a45a690dffa
@@ -3,6 +3,7 @@
3
3
  require 'ffi'
4
4
  require_relative 'core/options'
5
5
  require_relative 'sharing_options'
6
+ require_relative 'encryption_options'
6
7
  require_relative 'c_tanker/c_future'
7
8
  require_relative 'c_tanker/c_verification'
8
9
  require_relative 'c_tanker/c_verification_method'
@@ -59,8 +60,7 @@ module Tanker
59
60
  blocking_attach_function :tanker_encrypt, [:session_pointer, :pointer, :pointer, :uint64,
60
61
  Tanker::EncryptionOptions], CFuture
61
62
  blocking_attach_function :tanker_decrypt, [:session_pointer, :pointer, :pointer, :uint64], CFuture
62
- blocking_attach_function :tanker_share, [:session_pointer, :pointer, :uint64, :pointer, :uint64,
63
- :pointer, :uint64], CFuture
63
+ blocking_attach_function :tanker_share, [:session_pointer, :pointer, :uint32, Tanker::SharingOptions], CFuture
64
64
 
65
65
  blocking_attach_function :tanker_future_wait, [CFuture], :void
66
66
  blocking_attach_function :tanker_future_has_error, [CFuture], :bool
@@ -72,8 +72,7 @@ module Tanker
72
72
  blocking_attach_function :tanker_update_group_members, [:session_pointer, :string,
73
73
  :pointer, :uint64], CFuture
74
74
 
75
- blocking_attach_function :tanker_encryption_session_open, [:session_pointer, :pointer, :uint64,
76
- :pointer, :uint64], CFuture
75
+ blocking_attach_function :tanker_encryption_session_open, [:session_pointer, Tanker::EncryptionOptions], CFuture
77
76
  blocking_attach_function :tanker_encryption_session_close, [:enc_sess_pointer], CFuture
78
77
  blocking_attach_function :tanker_encryption_session_encrypted_size, [:uint64], :uint64
79
78
  blocking_attach_function :tanker_encryption_session_get_resource_id, [:enc_sess_pointer], CFuture
@@ -17,7 +17,11 @@ module Tanker::CTanker
17
17
 
18
18
  def self.new_cstring_array(strings)
19
19
  cstrings = FFI::MemoryPointer.new(:pointer, strings.length)
20
- cstrings.write_array_of_pointer(strings.map { |id| new_cstring id })
20
+ ruby_strings = strings.map { |id| new_cstring id }
21
+ # keep alive the ruby objects to prevent GC
22
+ # I could not find any other place to store these
23
+ cstrings.instance_variable_set(:@ruby_strings, ruby_strings)
24
+ cstrings.write_array_of_pointer(ruby_strings)
21
25
  cstrings
22
26
  end
23
27
 
@@ -59,31 +59,16 @@ module Tanker
59
59
  end
60
60
 
61
61
  cresource_ids = CTanker.new_cstring_array resource_ids
62
- cusers = sharing_options[:recipient_public_identities]
63
- nb_cusers = sharing_options[:nb_recipient_public_identities]
64
- cgroups = sharing_options[:recipient_group_ids]
65
- nb_cgroups = sharing_options[:nb_recipient_group_ids]
66
-
67
- CTanker.tanker_share(@ctanker, cusers, nb_cusers,
68
- cgroups, nb_cgroups,
69
- cresource_ids, resource_ids.length).get
62
+
63
+ CTanker.tanker_share(@ctanker, cresource_ids, resource_ids.length, sharing_options).get
70
64
  end
71
65
 
72
- def create_encryption_session(sharing_options = nil)
73
- if sharing_options.nil?
74
- cusers = nil
75
- nb_cusers = 0
76
- cgroups = nil
77
- nb_cgroups = 0
78
- else
79
- cusers = sharing_options[:recipient_public_identities]
80
- nb_cusers = sharing_options[:nb_recipient_public_identities]
81
- cgroups = sharing_options[:recipient_group_ids]
82
- nb_cgroups = sharing_options[:nb_recipient_group_ids]
66
+ def create_encryption_session(encryption_options = nil)
67
+ unless !encryption_options || encryption_options.is_a?(EncryptionOptions)
68
+ raise TypeError, "expected encryption_options to be a EncryptionOptions, but got a #{encryption_options.class}"
83
69
  end
84
70
 
85
- csession = CTanker.tanker_encryption_session_open(@ctanker, cusers, nb_cusers,
86
- cgroups, nb_cgroups).get
71
+ csession = CTanker.tanker_encryption_session_open(@ctanker, encryption_options).get
87
72
  EncryptionSession.new(csession)
88
73
  end
89
74
 
@@ -96,6 +81,10 @@ module Tanker
96
81
  private
97
82
 
98
83
  def encrypt_common(data, encryption_options = nil)
84
+ unless !encryption_options || encryption_options.is_a?(EncryptionOptions)
85
+ raise TypeError, "expected encryption_options to be a EncryptionOptions, but got a #{encryption_options.class}"
86
+ end
87
+
99
88
  inbuf = FFI::MemoryPointer.from_string(data)
100
89
 
101
90
  encrypted_size = CTanker.tanker_encrypted_size data.bytesize
@@ -74,7 +74,7 @@ module Tanker
74
74
  attach_ptr = CTanker.tanker_attach_provisional_identity(@ctanker, provisional_identity).get
75
75
  attach_status = attach_ptr.get(:uint8, 1)
76
76
  method_ptr = attach_ptr.get_pointer(FFI::Pointer.size)
77
- method = CTanker::CVerificationMethod.new(method_ptr).to_verification_method
77
+ method = (CTanker::CVerificationMethod.new(method_ptr).to_verification_method if method_ptr.address != 0)
78
78
  AttachResult.new attach_status, method
79
79
  end
80
80
 
@@ -6,7 +6,7 @@ require 'tanker/c_tanker'
6
6
  module Tanker
7
7
  class Core
8
8
  def encrypt_stream(stream, encryption_options = nil)
9
- Stream.do_stream_action(stream) { |cb| CTanker.tanker_stream_encrypt(@ctanker, cb, encryption_options, nil) }
9
+ Stream.do_stream_action(stream) { |cb| CTanker.tanker_stream_encrypt(@ctanker, cb, nil, encryption_options) }
10
10
  end
11
11
 
12
12
  def decrypt_stream(stream)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Tanker
4
4
  class Core
5
- VERSION = '2.4.0.alpha.9'
5
+ VERSION = '2.4.1.alpha.1'
6
6
 
7
7
  def self.native_version
8
8
  CTanker.tanker_version_string
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ffi'
4
+ require 'tanker/c_tanker/c_string'
5
+
6
+ module Tanker
7
+ # Options that can be given when encrypting data
8
+ class EncryptionOptions < FFI::Struct
9
+ def initialize(share_with_users: [], share_with_groups: [], share_with_self: true)
10
+ @users_objs = share_with_users.map { |id| CTanker.new_cstring id }
11
+ users = FFI::MemoryPointer.new(:pointer, share_with_users.length)
12
+ users.write_array_of_pointer(@users_objs)
13
+
14
+ @groups_objs = share_with_groups.map { |id| CTanker.new_cstring id }
15
+ groups = FFI::MemoryPointer.new(:pointer, share_with_groups.length)
16
+ groups.write_array_of_pointer(@groups_objs)
17
+
18
+ self[:version] = 3
19
+ self[:recipient_public_identities] = users
20
+ self[:nb_recipient_public_identities] = share_with_users.length
21
+ self[:recipient_group_ids] = groups
22
+ self[:nb_recipient_group_ids] = share_with_groups.length
23
+ self[:share_with_self] = share_with_self
24
+ end
25
+
26
+ layout :version, :uint8,
27
+ :recipient_public_identities, :pointer,
28
+ :nb_recipient_public_identities, :uint32,
29
+ :recipient_group_ids, :pointer,
30
+ :nb_recipient_group_ids, :uint32,
31
+ :share_with_self, :bool
32
+ end
33
+ end
@@ -4,39 +4,28 @@ require 'ffi'
4
4
  require 'tanker/c_tanker/c_string'
5
5
 
6
6
  module Tanker
7
- module CommonSharingOptions
7
+ # Options that can be given when sharing data
8
+ class SharingOptions < FFI::Struct
8
9
  def initialize(share_with_users: [], share_with_groups: [])
9
- @recipients = FFI::MemoryPointer.new(:pointer, share_with_users.length)
10
- @recipients.write_array_of_pointer(share_with_users.map { |id| CTanker.new_cstring id })
10
+ @users_objs = share_with_users.map { |id| CTanker.new_cstring id }
11
+ users = FFI::MemoryPointer.new(:pointer, share_with_users.length)
12
+ users.write_array_of_pointer(@users_objs)
11
13
 
12
- @groups = FFI::MemoryPointer.new(:pointer, share_with_groups.length)
13
- @groups.write_array_of_pointer(share_with_groups.map { |id| CTanker.new_cstring id })
14
+ @groups_objs = share_with_groups.map { |id| CTanker.new_cstring id }
15
+ groups = FFI::MemoryPointer.new(:pointer, share_with_groups.length)
16
+ groups.write_array_of_pointer(@groups_objs)
14
17
 
15
- self[:version] = 2
16
- self[:recipient_public_identities] = @recipients
18
+ self[:version] = 1
19
+ self[:recipient_public_identities] = users
17
20
  self[:nb_recipient_public_identities] = share_with_users.length
18
- self[:recipient_group_ids] = @groups
21
+ self[:recipient_group_ids] = groups
19
22
  self[:nb_recipient_group_ids] = share_with_groups.length
20
23
  end
21
24
 
22
- def self.included(base)
23
- base.layout :version, :uint8,
24
- :recipient_public_identities, :pointer,
25
- :nb_recipient_public_identities, :uint32,
26
- :recipient_group_ids, :pointer,
27
- :nb_recipient_group_ids, :uint32
28
- end
29
- end
30
-
31
- # Options that can be given when sharing data
32
- class SharingOptions < FFI::Struct
33
- include CommonSharingOptions
25
+ layout :version, :uint8,
26
+ :recipient_public_identities, :pointer,
27
+ :nb_recipient_public_identities, :uint32,
28
+ :recipient_group_ids, :pointer,
29
+ :nb_recipient_group_ids, :uint32
34
30
  end
35
-
36
- # Options that can be given when encrypting data
37
- class EncryptionOptions < FFI::Struct
38
- include CommonSharingOptions
39
- end
40
-
41
- private_constant :CommonSharingOptions
42
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanker-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0.alpha.9
4
+ version: 2.4.1.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanker team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-30 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -161,6 +161,7 @@ files:
161
161
  - lib/tanker/core/verification.rb
162
162
  - lib/tanker/core/verification_method.rb
163
163
  - lib/tanker/core/version.rb
164
+ - lib/tanker/encryption_options.rb
164
165
  - lib/tanker/error.rb
165
166
  - lib/tanker/sharing_options.rb
166
167
  - vendor/libctanker/linux64/tanker/lib/libctanker.so