tanker-core 2.6.2.beta.5 → 2.6.4.beta.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: efcde6b42dd49895c70ee3ee44cb264babe4a04b9b7e78d2176324074c732c1d
4
- data.tar.gz: 49d2e6e054b2f31d60d26d6a14cacb3630b50bc0f4ced5fe429c06a84bef3730
3
+ metadata.gz: a6c5dd1010b0940970116a71abbca56f4b4ca7556dd89fc5b31300afd9598efe
4
+ data.tar.gz: 77e8a24a8dfac4ec1c025b79cfd8de6c21c535288e44c9c0bc82943c4fdfc6d1
5
5
  SHA512:
6
- metadata.gz: '08a8e6f624847dc029f60d9982e36430e9c092a4e46a19001b6bb746a292a7c4aa34804751eefa0e1f5bed1565227fbb4e15e76f95016c46e5c2a35005fb8111'
7
- data.tar.gz: 2f327f018c834da477bec4a21e46936eb5ee72f0824110ea4035583b675f78f5e37d5d30e3f1108b11cd32b0be62c9573bfde9e1597ba085ebdbb118e59ddced
6
+ metadata.gz: 76a204e29d2b26da3ccf1e2728544dbc7ba6461e25d3833d11f7d6c5a63726a4d6790c33077242ea1edf89ca6e30432bd4c30f668bc0b1be8da52eecfb6ebbc6
7
+ data.tar.gz: 89be9cc1fd40575a8f5b82ba3c216b7aeaef82456f1cd30a2970693582da1bedd023a401709943586abdf834c059db81cb09cfd957e24f85924f12ca54c654d3
@@ -25,7 +25,7 @@ module Tanker
25
25
  CTanker.tanker_future_wait @cfuture
26
26
  if CTanker.tanker_future_has_error @cfuture
27
27
  cerr = CTanker.tanker_future_get_error @cfuture
28
- raise Error, cerr
28
+ raise Error.from_ctanker_error(cerr)
29
29
  else
30
30
  CTanker.tanker_future_get_voidptr @cfuture
31
31
  end
@@ -186,6 +186,8 @@ module Tanker
186
186
 
187
187
  def init_io
188
188
  read, @write = IO.pipe
189
+ @write.binmode
190
+ read.binmode
189
191
 
190
192
  # The user will only read on the pipe, so we need something that reads
191
193
  # from Tanker and writes to the pipe, it's this thread.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Tanker
4
4
  class Core
5
- VERSION = '2.6.2.beta.5'
5
+ VERSION = '2.6.4.beta.1'
6
6
 
7
7
  def self.native_version
8
8
  CTanker.tanker_version_string
@@ -3,33 +3,79 @@
3
3
  require 'tanker/c_tanker/c_tanker_error'
4
4
 
5
5
  module Tanker
6
- # Errors returned by native tanker futures
6
+ # Main error class for errors returned by native tanker futures
7
7
  class Error < StandardError
8
- NO_ERROR = 0
8
+ attr_reader :code
9
+ attr_reader :message
10
+
11
+ def initialize(ctanker_error)
12
+ @code = ctanker_error[:error_code]
13
+ @message = ctanker_error[:error_message]
14
+ super(@message)
15
+ end
16
+
17
+ # Error code constants
9
18
  INVALID_ARGUMENT = 1
10
19
  INTERNAL_ERROR = 2
11
20
  NETWORK_ERROR = 3
12
21
  PRECONDITION_FAILED = 4
13
22
  OPERATION_CANCELED = 5
14
-
15
23
  DECRYPTION_FAILED = 6
16
-
17
24
  GROUP_TOO_BIG = 7
18
-
19
25
  INVALID_VERIFICATION = 8
20
26
  TOO_MANY_ATTEMPTS = 9
21
27
  EXPIRED_VERIFICATION = 10
22
28
  IO_ERROR = 11
23
29
  DEVICE_REVOKED = 12
24
-
25
30
  CONFLICT = 13
26
31
 
27
- def initialize(ctanker_error)
28
- @code = ctanker_error[:error_code]
29
- @message = ctanker_error[:error_message]
30
- end
32
+ # Error subclasses
33
+ class InvalidArgument < self; end
34
+ class InternalError < self; end
35
+ class NetworkError < self; end
36
+ class PreconditionFailed < self; end
37
+ class OperationCanceled < self; end
38
+ class DecryptionFailed < self; end
39
+ class GroupTooBig < self; end
40
+ class InvalidVerification < self; end
41
+ class TooManyAttempts < self; end
42
+ class ExpiredVerification < self; end
43
+ class IOError < self; end
44
+ class DeviceRevoked < self; end
45
+ class Conflict < self; end
31
46
 
32
- attr_reader :code
33
- attr_reader :message
47
+ class << self
48
+ ERROR_CODE_TO_CLASS = {
49
+ INVALID_ARGUMENT => InvalidArgument,
50
+ INTERNAL_ERROR => InternalError,
51
+ NETWORK_ERROR => NetworkError,
52
+ PRECONDITION_FAILED => PreconditionFailed,
53
+ OPERATION_CANCELED => OperationCanceled,
54
+ DECRYPTION_FAILED => DecryptionFailed,
55
+ GROUP_TOO_BIG => GroupTooBig,
56
+ INVALID_VERIFICATION => InvalidVerification,
57
+ TOO_MANY_ATTEMPTS => TooManyAttempts,
58
+ EXPIRED_VERIFICATION => ExpiredVerification,
59
+ IO_ERROR => IOError,
60
+ DEVICE_REVOKED => DeviceRevoked,
61
+ CONFLICT => Conflict
62
+ }.freeze
63
+
64
+ private_constant :ERROR_CODE_TO_CLASS
65
+
66
+ def from_ctanker_error(ctanker_error)
67
+ error_code = ctanker_error[:error_code]
68
+ error_class = ERROR_CODE_TO_CLASS[error_code]
69
+
70
+ if error_class.nil?
71
+ InternalError.new(
72
+ error_code: INTERNAL_ERROR,
73
+ error_message: "Unknown error code returned by ctanker: #{error_code} - #{ctanker_error[:error_message]}"
74
+ )
75
+ else
76
+ error_class.new ctanker_error
77
+ end
78
+ end
79
+ end
34
80
  end
35
81
  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.6.2.beta.5
4
+ version: 2.6.4.beta.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-11-10 00:00:00.000000000 Z
11
+ date: 2020-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi