tanker-core 2.32.0.alpha.1 → 2.32.0.beta.2

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: 8e5a0c66b4e62fa57f6f1328caf7e90da7a93c546152097298dfeb198e79fac4
4
- data.tar.gz: c1b5008343b5d95f0e2186490d7bde0591dad6f1789dfe5928747dece991c2f1
3
+ metadata.gz: 58ecc5854b8a1df78015933a12b40c24701f7d9d46425939178097ec8861d0e1
4
+ data.tar.gz: a84443d60fadfe6dd7ab84b47850accd40ffbf0e237b6b72606753d8011f1f77
5
5
  SHA512:
6
- metadata.gz: 65996653c8d1843bdfaabc351ca0f65660cb97f42dff27421360ed6b44080e53c0f9c3795e998ba3eea1bdc96c59d2527fbaa2da1ecf506ce06c4ce3ed7e6298
7
- data.tar.gz: 80b2d2d64871d6b1deb15cd19d9c7d111fa5e0df75a5bcad4836bbd30a838858498dbfab0fb81f7ce8914bf2635076cdf9d245cb078ff6203d89d1d2aef35f4c
6
+ metadata.gz: cf0f2020ec774886f32b8e3558de12fbeb1b1c712f815c81826f9598d8a88733002054851556f97cb852a62d7b8f81239bddf1e2c572cca976f60a521fbd3663
7
+ data.tar.gz: 5e7b2549806a0718091223d2ab088e477a926dc57ff712065782ea025b474a258dab52a1f713ecd8b8a29e1aef6bcbe957fc72e462405d126cd430a5cc0d3991
@@ -48,6 +48,7 @@ module Tanker
48
48
  :verification_key, :pointer,
49
49
  :email_verification, CEmailVerification,
50
50
  :passphrase, :pointer,
51
+ :e2e_passphrase, :pointer,
51
52
  :oidc_id_token, :pointer,
52
53
  :phone_number_verification, CPhoneNumberVerification,
53
54
  :preverified_email, :pointer,
@@ -60,6 +61,7 @@ module Tanker
60
61
  TYPE_PHONE_NUMBER = 5
61
62
  TYPE_PREVERIFIED_EMAIL = 6
62
63
  TYPE_PREVERIFIED_PHONE_NUMBER = 7
64
+ TYPE_E2E_PASSPHRASE = 8
63
65
 
64
66
  def initialize(verification) # rubocop:disable Metrics/CyclomaticComplexity Not relevant for a case/when
65
67
  super()
@@ -97,11 +99,15 @@ module Tanker
97
99
  @preverified_phone_number = CTanker.new_cstring verification.preverified_phone_number
98
100
  self[:type] = TYPE_PREVERIFIED_PHONE_NUMBER
99
101
  self[:preverified_phone_number] = @preverified_phone_number
102
+ when Tanker::E2ePassphraseVerification
103
+ @e2e_passphrase = CTanker.new_cstring verification.e2e_passphrase
104
+ self[:type] = TYPE_E2E_PASSPHRASE
105
+ self[:e2e_passphrase] = @e2e_passphrase
100
106
  else
101
107
  raise ArgumentError, 'Unknown Tanker::Verification type!'
102
108
  end
103
109
 
104
- self[:version] = 5
110
+ self[:version] = 6
105
111
  end
106
112
  end
107
113
 
@@ -18,6 +18,7 @@ module Tanker
18
18
  TYPE_PHONE_NUMBER = 5
19
19
  TYPE_PREVERIFIED_EMAIL = 6
20
20
  TYPE_PREVERIFIED_PHONE_NUMBER = 7
21
+ TYPE_E2E_PASSPHRASE = 8
21
22
 
22
23
  def to_verification_method # rubocop:disable Metrics/CyclomaticComplexity Not relevant for a case/when
23
24
  case self[:type]
@@ -35,6 +36,8 @@ module Tanker
35
36
  PreverifiedEmailVerificationMethod.new(self[:value].read_string.force_encoding(Encoding::UTF_8))
36
37
  when TYPE_PREVERIFIED_PHONE_NUMBER
37
38
  PreverifiedPhoneNumberVerificationMethod.new(self[:value].read_string.force_encoding(Encoding::UTF_8))
39
+ when TYPE_E2E_PASSPHRASE
40
+ E2ePassphraseVerificationMethod.new
38
41
  else
39
42
  raise "Unknown VerificationMethod type #{self[:type]}!"
40
43
  end
@@ -47,7 +47,7 @@ module Tanker
47
47
  blocking_attach_function :tanker_attach_provisional_identity, [:session_pointer, :string], CFuture
48
48
  blocking_attach_function :tanker_verify_provisional_identity, [:session_pointer, CVerification], CFuture
49
49
 
50
- blocking_attach_function :tanker_encrypted_size, [:uint64], :uint64
50
+ blocking_attach_function :tanker_encrypted_size, [:uint64, :uint32], :uint64
51
51
  blocking_attach_function :tanker_decrypted_size, [:pointer, :uint64], CFuture
52
52
  blocking_attach_function :tanker_get_resource_id, [:pointer, :uint64], CFuture
53
53
 
@@ -68,7 +68,7 @@ module Tanker
68
68
 
69
69
  blocking_attach_function :tanker_encryption_session_open, [:session_pointer, Tanker::EncryptionOptions], CFuture
70
70
  blocking_attach_function :tanker_encryption_session_close, [:enc_sess_pointer], CFuture
71
- blocking_attach_function :tanker_encryption_session_encrypted_size, [:uint64], :uint64
71
+ blocking_attach_function :tanker_encryption_session_encrypted_size, [:enc_sess_pointer, :uint64], :uint64
72
72
  blocking_attach_function :tanker_encryption_session_get_resource_id, [:enc_sess_pointer], CFuture
73
73
  blocking_attach_function :tanker_encryption_session_encrypt, [:enc_sess_pointer, :pointer,
74
74
  :pointer, :uint64], CFuture
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'tanker/c_tanker'
4
+ require 'tanker/encryption_options'
4
5
  require_relative 'encryption_session'
5
6
 
6
7
  module Tanker
@@ -80,17 +81,19 @@ module Tanker
80
81
 
81
82
  private
82
83
 
83
- def encrypt_common(data, encryption_options = nil)
84
- unless !encryption_options || encryption_options.is_a?(EncryptionOptions)
84
+ def encrypt_common(data, encryption_options)
85
+ unless encryption_options.nil? || encryption_options.is_a?(EncryptionOptions)
85
86
  raise TypeError, "expected encryption_options to be a EncryptionOptions, but got a #{encryption_options.class}"
86
87
  end
87
88
 
88
89
  inbuf = FFI::MemoryPointer.from_string(data)
89
90
 
90
- encrypted_size = CTanker.tanker_encrypted_size data.bytesize
91
+ options = encryption_options || EncryptionOptions.new
92
+
93
+ encrypted_size = CTanker.tanker_encrypted_size(data.bytesize, options[:padding_step])
91
94
  outbuf = FFI::MemoryPointer.new(:char, encrypted_size)
92
95
 
93
- CTanker.tanker_encrypt(@ctanker, outbuf, inbuf, data.bytesize, encryption_options).get
96
+ CTanker.tanker_encrypt(@ctanker, outbuf, inbuf, data.bytesize, options).get
94
97
 
95
98
  outbuf.read_string encrypted_size
96
99
  end
@@ -33,7 +33,7 @@ module Tanker
33
33
  def encrypt_common(data)
34
34
  inbuf = FFI::MemoryPointer.from_string(data)
35
35
 
36
- encrypted_size = CTanker.tanker_encryption_session_encrypted_size data.bytesize
36
+ encrypted_size = CTanker.tanker_encryption_session_encrypted_size(@csession, data.bytesize)
37
37
  outbuf = FFI::MemoryPointer.new(:char, encrypted_size)
38
38
 
39
39
  CTanker.tanker_encryption_session_encrypt(@csession, outbuf, inbuf, data.bytesize).get
@@ -93,4 +93,16 @@ module Tanker
93
93
  @preverified_phone_number = preverified_phone_number
94
94
  end
95
95
  end
96
+
97
+ class E2ePassphraseVerification < Verification
98
+ attr_reader :e2e_passphrase
99
+
100
+ def initialize(e2e_passphrase)
101
+ super()
102
+
103
+ ASSERT_UTF8.call(e2e_passphrase)
104
+
105
+ @e2e_passphrase = e2e_passphrase
106
+ end
107
+ end
96
108
  end
@@ -64,4 +64,6 @@ module Tanker
64
64
  super && preverified_phone_number == other.preverified_phone_number
65
65
  end
66
66
  end
67
+
68
+ class E2ePassphraseVerificationMethod < VerificationMethod; end
67
69
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Tanker
4
4
  class Core
5
- VERSION = '2.32.0.alpha.1'
5
+ VERSION = '2.32.0.beta.2'
6
6
 
7
7
  def self.native_version
8
8
  CTanker.tanker_version_string
@@ -6,7 +6,8 @@ require 'tanker/c_tanker/c_string'
6
6
  module Tanker
7
7
  # Options that can be given when encrypting data
8
8
  class EncryptionOptions < FFI::Struct
9
- def initialize(share_with_users: [], share_with_groups: [], share_with_self: true)
9
+ def initialize(share_with_users: [], share_with_groups: [], share_with_self: true,
10
+ padding_step: Padding::AUTO)
10
11
  super()
11
12
 
12
13
  @users_objs = share_with_users.map { |id| CTanker.new_cstring id }
@@ -17,12 +18,13 @@ module Tanker
17
18
  groups = FFI::MemoryPointer.new(:pointer, share_with_groups.length)
18
19
  groups.write_array_of_pointer(@groups_objs)
19
20
 
20
- self[:version] = 3
21
+ self[:version] = 4
21
22
  self[:recipient_public_identities] = users
22
23
  self[:nb_recipient_public_identities] = share_with_users.length
23
24
  self[:recipient_group_ids] = groups
24
25
  self[:nb_recipient_group_ids] = share_with_groups.length
25
26
  self[:share_with_self] = share_with_self
27
+ self[:padding_step] = padding_step.native_value
26
28
  end
27
29
 
28
30
  layout :version, :uint8,
@@ -30,6 +32,33 @@ module Tanker
30
32
  :nb_recipient_public_identities, :uint32,
31
33
  :recipient_group_ids, :pointer,
32
34
  :nb_recipient_group_ids, :uint32,
33
- :share_with_self, :bool
35
+ :share_with_self, :bool,
36
+ :padding_step, :uint32
37
+ end
38
+
39
+ class Padding
40
+ private_class_method :new
41
+ attr_reader :native_value
42
+
43
+ def initialize(native_value)
44
+ super()
45
+ @native_value = native_value
46
+ end
47
+
48
+ AUTO = new 0
49
+ OFF = new 1
50
+
51
+ def self.step(value)
52
+ unless value.is_a?(Integer)
53
+ raise TypeError,
54
+ "expected step to be an Integer >= 2, but got a #{value.class}"
55
+ end
56
+ unless value >= 2
57
+ raise ArgumentError,
58
+ "expected step to be an Integer >= 2, but got #{value}"
59
+ end
60
+
61
+ new(value)
62
+ end
34
63
  end
35
64
  end
@@ -5,14 +5,16 @@ require 'ffi'
5
5
  module Tanker
6
6
  # Options that can be given when using a verification method
7
7
  class VerificationOptions < FFI::Struct
8
- def initialize(with_session_token: false)
8
+ def initialize(with_session_token: false, allow_e2e_method_switch: false)
9
9
  super()
10
10
 
11
- self[:version] = 1
11
+ self[:version] = 2
12
12
  self[:with_session_token] = with_session_token ? 1 : 0
13
+ self[:allow_e2e_method_switch] = allow_e2e_method_switch ? 1 : 0
13
14
  end
14
15
 
15
16
  layout :version, :uint8,
16
- :with_session_token, :uint8
17
+ :with_session_token, :uint8,
18
+ :allow_e2e_method_switch, :uint8
17
19
  end
18
20
  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.32.0.alpha.1
4
+ version: 2.32.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanker team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-08 00:00:00.000000000 Z
11
+ date: 2022-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi