tanker-core 2.6.3.beta.1 → 2.6.5.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: b340cd6c68ae50a570cb9b2fe022cef3e58d977ea496f6a9a9188805dbcefc8f
4
- data.tar.gz: '08ed2f6c92839b80f1ad99298affcc5346baa1dd54cec35140a49dcbf1ea53af'
3
+ metadata.gz: 46c74066a15edece4c68df49ddbd87efeaf456624c35317371ed384081dcb07f
4
+ data.tar.gz: 4cb44ae9ed0bb54ad98c552396a5620256c227e1a39a896d652b026838ae3798
5
5
  SHA512:
6
- metadata.gz: db46bd49eef92e19a889758223a1ca7e187fefd2db5a47fbefd44f990a61a34ca57133bb01683130293c6830805e53b92ca7362538ca00aee4babc08600a7d50
7
- data.tar.gz: 841f15d5be8536cca1426ce9e56696c8f053a3684d93ecefdb9f944caf6fc5411aaed74a416c3822495bf26cee104389918df00dda706e955430fe213e6deafd
6
+ metadata.gz: 9321516dc25adff4033a4055d37ddc6dcfc4ef3802b039d944bf6a669bee833923d046a68be92e0a78b96480fdea0ec00878a40eb917a33e110cd0f2eff3cb1b
7
+ data.tar.gz: b19fccf5af7777cd8fba9ccc0282a2244126ccf727231cf091967e45e338e47f142ac1996cea433d44d09f479bd22ca17a428fc7b335532fa450f25f960428c3
@@ -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.3.beta.1'
5
+ VERSION = '2.6.5.beta.1'
6
6
 
7
7
  def self.native_version
8
8
  CTanker.tanker_version_string
@@ -3,33 +3,82 @@
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
31
+ UPGRADE_REQUIRED = 14
26
32
 
27
- def initialize(ctanker_error)
28
- @code = ctanker_error[:error_code]
29
- @message = ctanker_error[:error_message]
30
- end
33
+ # Error subclasses
34
+ class InvalidArgument < self; end
35
+ class InternalError < self; end
36
+ class NetworkError < self; end
37
+ class PreconditionFailed < self; end
38
+ class OperationCanceled < self; end
39
+ class DecryptionFailed < self; end
40
+ class GroupTooBig < self; end
41
+ class InvalidVerification < self; end
42
+ class TooManyAttempts < self; end
43
+ class ExpiredVerification < self; end
44
+ class IOError < self; end
45
+ class DeviceRevoked < self; end
46
+ class Conflict < self; end
47
+ class UpgradeRequired < self; end
31
48
 
32
- attr_reader :code
33
- attr_reader :message
49
+ class << self
50
+ ERROR_CODE_TO_CLASS = {
51
+ INVALID_ARGUMENT => InvalidArgument,
52
+ INTERNAL_ERROR => InternalError,
53
+ NETWORK_ERROR => NetworkError,
54
+ PRECONDITION_FAILED => PreconditionFailed,
55
+ OPERATION_CANCELED => OperationCanceled,
56
+ DECRYPTION_FAILED => DecryptionFailed,
57
+ GROUP_TOO_BIG => GroupTooBig,
58
+ INVALID_VERIFICATION => InvalidVerification,
59
+ TOO_MANY_ATTEMPTS => TooManyAttempts,
60
+ EXPIRED_VERIFICATION => ExpiredVerification,
61
+ IO_ERROR => IOError,
62
+ DEVICE_REVOKED => DeviceRevoked,
63
+ CONFLICT => Conflict,
64
+ UPGRADE_REQUIRED => UpgradeRequired
65
+ }.freeze
66
+
67
+ private_constant :ERROR_CODE_TO_CLASS
68
+
69
+ def from_ctanker_error(ctanker_error)
70
+ error_code = ctanker_error[:error_code]
71
+ error_class = ERROR_CODE_TO_CLASS[error_code]
72
+
73
+ if error_class.nil?
74
+ InternalError.new(
75
+ error_code: INTERNAL_ERROR,
76
+ error_message: "Unknown error code returned by ctanker: #{error_code} - #{ctanker_error[:error_message]}"
77
+ )
78
+ else
79
+ error_class.new ctanker_error
80
+ end
81
+ end
82
+ end
34
83
  end
35
84
  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.3.beta.1
4
+ version: 2.6.5.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-18 00:00:00.000000000 Z
11
+ date: 2020-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi