aws-crt 0.1.5-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a83fe0dd52deaf2a2a5295dadd3e44184b3f2b64e92ab7055b79b44aa81d2134
4
+ data.tar.gz: 1780f7fe5f3730c1937bedd7d18be15b0a8a8680d1b251688a80f1952ea74a4d
5
+ SHA512:
6
+ metadata.gz: d6424570a965e922a5aad41df20658a90255ef42cdab9f6a903f4dae166fdc2ddbbbc09e556dcdd5fc233f209b22e227997b9350b100748657ab1cb22780b43c
7
+ data.tar.gz: 986f4beef06ad8400e18e5179252b0b34955d31a92983f8520a7c44af7c5c4b9d0de59249f11c1c2367c810467fc29528a1fe4e51d0036ce5ba36312ae6bf3be
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ Unreleased Changes
2
+ ------------------
3
+
4
+ 0.1.5 (2022-04-05)
5
+ ------------------
6
+
7
+ * Issue - Update to the latest aws-crt-ffi.
8
+
9
+ 0.1.4 (2022-03-15)
10
+ ------------------
11
+
12
+ * Issue - Update the aws-lc submodule to a version that is not vulnerable to OpenSSL CVE-2022-0778 - Possible infinite loop in BN_mod_sqrt()
13
+
14
+ 0.1.0 (2021-08-04)
15
+ ------------------
16
+
17
+ * Feature - Initial preview release of `aws-crt` gem.
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.5
Binary file
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ module Auth
6
+ # CRT CredentialOptions
7
+ class CredentialsOptions
8
+ include Aws::Crt::ManagedNative
9
+ native_destroy Aws::Crt::Native.method(:credentials_options_release)
10
+
11
+ UINT64_MAX = 18_446_744_073_709_551_615
12
+
13
+ # @param [String] access_key_id
14
+ # @param [String] secret_access_key
15
+ # @param [String] session_token (nil)
16
+ # @param [Time|int] expiration (nil) - Either a Time or an int
17
+ # seconds since unix epoch
18
+ def initialize(access_key_id, secret_access_key,
19
+ session_token = nil, expiration = nil)
20
+ if !access_key_id || access_key_id.empty?
21
+ raise ArgumentError, 'access_key_id must be set'
22
+ end
23
+
24
+ if !secret_access_key || secret_access_key.empty?
25
+ raise ArgumentError, 'secret_access_key must be set'
26
+ end
27
+
28
+ manage_native do
29
+ Aws::Crt::Native.credentials_options_new
30
+ end
31
+
32
+ Aws::Crt::Native.credentials_options_set_access_key_id(
33
+ native, access_key_id, access_key_id.length
34
+ )
35
+
36
+ Aws::Crt::Native.credentials_options_set_secret_access_key(
37
+ native, secret_access_key, secret_access_key.length
38
+ )
39
+
40
+ if session_token && !session_token.empty?
41
+ Aws::Crt::Native.credentials_options_set_session_token(
42
+ native, session_token, session_token.length
43
+ )
44
+ end
45
+
46
+ Aws::Crt::Native.credentials_options_set_expiration_timepoint_seconds(
47
+ native, expiration&.to_i || UINT64_MAX
48
+ )
49
+ end
50
+ end
51
+
52
+ # Utility class for Credentials.
53
+ class Credentials
54
+ include Aws::Crt::ManagedNative
55
+ native_destroy Aws::Crt::Native.method(:credentials_release)
56
+
57
+ # @param [String] access_key_id
58
+ # @param [String] secret_access_key
59
+ # @param [String] session_token (nil)
60
+ # @param [Time|int] expiration (nil) - Either a Time or an int
61
+ # seconds since unix epoch
62
+ def initialize(access_key_id, secret_access_key,
63
+ session_token = nil, expiration = nil)
64
+
65
+ credential_options = CredentialsOptions.new(
66
+ access_key_id, secret_access_key,
67
+ session_token, expiration
68
+ )
69
+ manage_native do
70
+ Aws::Crt::Native.credentials_new(
71
+ credential_options.native
72
+ )
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ module Auth
6
+ # Signing Config
7
+ class Signable
8
+ include Aws::Crt::ManagedNative
9
+ native_destroy Aws::Crt::Native.method(:signable_release)
10
+
11
+ # @param [Http::Message] http_request
12
+ def initialize(http_request)
13
+ manage_native do
14
+ Aws::Crt::Native.signable_new_from_http_request(http_request.native)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ # High level Ruby abstractions for CRT Auth functionality
6
+ module Auth
7
+ # Ruby interface to CRT signing functions
8
+ module Signer
9
+ # Sign a request
10
+ # @param [SigningConfig] - SigningConfig to apply to this signature
11
+ # @param [Signable] - Signable object (request) to sign.
12
+ #
13
+ # @return [Hash] Return a hash with keys:
14
+ # * signature[String] - the computed signature
15
+ # * headers[Hash] - signed headers, including the `Authorization`
16
+ # header.
17
+ def self.sign_request(
18
+ signing_config, signable, method = 'default', path = 'default'
19
+ )
20
+ out = {}
21
+ callback = proc do |result, status, _userdata|
22
+ Aws::Crt::Errors.raise_last_error unless status.zero?
23
+ http_request = Http::Message.new(method, path)
24
+ Aws::Crt::Native.signing_result_apply_to_http_request(
25
+ result,
26
+ http_request.native
27
+ )
28
+ out[:path] = http_request.path
29
+ out[:headers] = http_request.headers
30
+ if (auth = out[:headers]['Authorization']) &&
31
+ (match = /Signature=([a-f0-9]+)/.match(auth))
32
+ out[:signature] = match[1]
33
+ end
34
+ out[:http_request] = http_request
35
+
36
+ nil
37
+ end
38
+
39
+ # Currently this will always be synchronous
40
+ # (because we are resolving credentials) - so do not need to
41
+ # sync threads/callbacks
42
+ Aws::Crt::Native.sign_request_aws(
43
+ signable.native, signing_config.native, callback, nil
44
+ )
45
+ out
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Aws
6
+ module Crt
7
+ module Auth
8
+ # Signing Config
9
+ class SigningConfig
10
+ include Aws::Crt::ManagedNative
11
+ native_destroy Aws::Crt::Native.method(:signing_config_aws_release)
12
+
13
+ # @param [Hash] options
14
+ # @option options [required, Aws::Crt::Native::signing_algorithm]
15
+ # :algorithm
16
+ # @option options [required, Aws::Crt::Native::signature_type]
17
+ # :signature_type
18
+ # @option options [required, Credentials] :credentials
19
+ # @option options [required, String] :region
20
+ # @option options [required, String] :service
21
+ # @option options [Time] :date (Time.now)
22
+ # @option options [Array<String>]
23
+ # :unsigned_headers ([])
24
+ # @option options [Boolean] :use_double_uri_encode (false)
25
+ # @option options [Boolean] :should_normalize_uri_path (false)
26
+ # @option options [Boolean] :omit_session_token (false)
27
+
28
+ # @option options [Boolean] :signed_body_header_type
29
+ # (:sbht_content_sha256) -
30
+ # Controls if signing adds a header containing the
31
+ # canonical request's body value
32
+ # @option options [String] :signed_body_value - Optional string to use
33
+ # as the canonical request's body value. If string is empty, a value
34
+ # will be calculated from the payload during signing. Typically,
35
+ # this is the SHA-256 of the (request/chunk/event) payload,
36
+ # written as lowercase hex. If this has been precalculated, it can
37
+ # be set here. Special values used by certain services can also
38
+ # be set (e.g. "UNSIGNED-PAYLOAD"
39
+ # "STREAMING-AWS4-HMAC-SHA256-PAYLOAD"
40
+ # "STREAMING-AWS4-HMAC-SHA256-EVENTS").
41
+ # @option options[Integer] :expiration_in_seconds (0) -
42
+ # If non-zero and the
43
+ # signing transform is query param, then signing will add
44
+ # X-Amz-Expires to the query string, equal to the value
45
+ # specified here. If this value is zero or if header signing
46
+ # is being used then this parameter has no effect.
47
+ def initialize(options = {})
48
+ # validation of parameters is handled in signing_config_new
49
+
50
+ # create a callback function for aws_should_sign_header_fn
51
+ @sign_header_fn = extract_unsigned_header_fn(
52
+ options[:unsigned_headers]
53
+ )
54
+
55
+ signed_body_header_type = options.fetch(
56
+ :signed_body_header_type,
57
+ :sbht_content_sha256
58
+ )
59
+
60
+ # ensure we retain a reference to the credentials to avoid GC
61
+ @credentials = options[:credentials]
62
+ manage_native do
63
+ Aws::Crt::Native.signing_config_aws_new
64
+ end
65
+
66
+ Aws::Crt::Native.signing_config_aws_set_algorithm(native, options[:algorithm])
67
+ Aws::Crt::Native.signing_config_aws_set_signature_type(native, options[:signature_type])
68
+ Aws::Crt::Native.signing_config_aws_set_region(native, options[:region], options[:region].length)
69
+ Aws::Crt::Native.signing_config_aws_set_service(native, options[:service], options[:service].length)
70
+ Aws::Crt::Native.signing_config_aws_set_date(native, extract_date(options))
71
+ Aws::Crt::Native.signing_config_aws_set_credentials_provider(native, @credentials&.native)
72
+ Aws::Crt::Native.signing_config_aws_set_signed_body_header_type(native, signed_body_header_type)
73
+ if @sign_header_fn
74
+ Aws::Crt::Native.signing_config_aws_set_should_sign_header_fn(native, @sign_header_fn)
75
+ end
76
+
77
+ assign_body_value(options)
78
+ assign_flags(options)
79
+
80
+ validate_config!
81
+ end
82
+
83
+ private
84
+
85
+ def extract_date(options)
86
+ (options[:date] || Time.now).to_i
87
+ end
88
+
89
+ def extract_unsigned_header_fn(unsigned_headers)
90
+ return nil unless unsigned_headers&.size&.positive?
91
+
92
+ unsigned_headers = Set.new(unsigned_headers.map(&:downcase))
93
+ proc do |param_ptr, len, _p|
94
+ param = param_ptr.read_string(len)
95
+ !unsigned_headers.include? param.to_s.downcase
96
+ end
97
+ end
98
+
99
+ def assign_flags(options)
100
+ Aws::Crt::Native.signing_config_aws_set_use_double_uri_encode(native, options.fetch(:use_double_uri_encode, false))
101
+ Aws::Crt::Native.signing_config_aws_set_should_normalize_uri_path(native, options.fetch(:should_normalize_uri_path, false))
102
+ Aws::Crt::Native.signing_config_aws_set_omit_session_token(native, options.fetch(:omit_session_token, false))
103
+ Aws::Crt::Native.signing_config_aws_set_expiration_in_seconds(native, options.fetch(:expiration_in_seconds, 0))
104
+ end
105
+
106
+ def assign_body_value(options)
107
+ if options[:signed_body_value]
108
+ Aws::Crt::Native.signing_config_aws_set_signed_body_value(native, options[:signed_body_value], options[:signed_body_value].length)
109
+ end
110
+ end
111
+
112
+ def validate_config!
113
+ unless Aws::Crt::Native.signing_config_aws_validate(native)
114
+ # validate returns a boolean rather than int to indicate status
115
+ # but still sets the exception
116
+ Errors.raise_last_error
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ module Auth
6
+ # CRT CredentialOptions
7
+ class StaticCredentialsProviderOptions
8
+ include Aws::Crt::ManagedNative
9
+ native_destroy Aws::Crt::Native.method(:credentials_provider_static_options_release)
10
+
11
+ # @param [String] access_key_id
12
+ # @param [String] secret_access_key
13
+ # @param [String] session_token (nil)
14
+ def initialize(access_key_id, secret_access_key,
15
+ session_token = nil)
16
+ if !access_key_id || access_key_id.empty?
17
+ raise ArgumentError, 'access_key_id must be set'
18
+ end
19
+
20
+ if !secret_access_key || secret_access_key.empty?
21
+ raise ArgumentError, 'secret_access_key must be set'
22
+ end
23
+
24
+ manage_native do
25
+ Aws::Crt::Native.credentials_provider_static_options_new
26
+ end
27
+
28
+ Aws::Crt::Native.credentials_provider_static_options_set_access_key_id(
29
+ native, access_key_id, access_key_id.length
30
+ )
31
+
32
+ Aws::Crt::Native.credentials_provider_static_options_set_secret_access_key(
33
+ native, secret_access_key, secret_access_key.length
34
+ )
35
+
36
+ if session_token && !session_token.empty?
37
+ Aws::Crt::Native.credentials_provider_static_options_set_session_token(
38
+ native, session_token, session_token.length
39
+ )
40
+ end
41
+ end
42
+ end
43
+
44
+ # Utility class for Credentials.
45
+ class StaticCredentialsProvider
46
+ include Aws::Crt::ManagedNative
47
+ native_destroy Aws::Crt::Native.method(:credentials_provider_release)
48
+
49
+ # @param [String] access_key_id
50
+ # @param [String] secret_access_key
51
+ # @param [String] session_token (nil)
52
+ def initialize(access_key_id, secret_access_key,
53
+ session_token = nil)
54
+
55
+ credential_options = StaticCredentialsProviderOptions.new(
56
+ access_key_id, secret_access_key,
57
+ session_token
58
+ )
59
+ manage_native do
60
+ Aws::Crt::Native.credentials_provider_static_new(
61
+ credential_options.native
62
+ )
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ # High level Ruby abstractions for CRT Checksums functionality
6
+ module Checksums
7
+ def self.crc32(str, previous = 0)
8
+ Aws::Crt::Native.crc32(
9
+ FFI::MemoryPointer.from_string(str),
10
+ str.size,
11
+ previous
12
+ )
13
+ end
14
+
15
+ def self.crc32c(str, previous = 0)
16
+ Aws::Crt::Native.crc32c(
17
+ FFI::MemoryPointer.from_string(str),
18
+ str.size,
19
+ previous
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Crt
5
+ # Base class for CRT Errors
6
+ class Error < StandardError
7
+ end
8
+
9
+ # CRT Errors - includes utilities for mapping errors from CRT to
10
+ # Ruby Exceptions
11
+ module Errors
12
+ @const_set_mutex = Mutex.new
13
+
14
+ AWS_TO_RUBY_ERROR_MAP = {
15
+ 'AWS_ERROR_INVALID_INDEX' => IndexError,
16
+ 'AWS_ERROR_OOM' => NoMemoryError,
17
+ 'AWS_ERROR_UNIMPLEMENTED' => NotImplementedError,
18
+ 'AWS_ERROR_INVALID_ARGUMENT' => ArgumentError,
19
+ 'AWS_ERROR_SYS_CALL_FAILURE' => SystemCallError,
20
+ 'AWS_ERROR_DIVIDE_BY_ZERO' => ZeroDivisionError,
21
+ 'AWS_ERROR_HASHTBL_ITEM_NOT_FOUND' => KeyError
22
+ }.freeze
23
+
24
+ def self.raise_last_error
25
+ error_code = Aws::Crt::Native.last_error
26
+ return if error_code.zero?
27
+
28
+ error_name = Aws::Crt::Native.error_name(error_code)
29
+ msg = Aws::Crt::Native.error_debug_str(error_code)
30
+ Aws::Crt::Native.reset_error
31
+ raise error_class(error_name), msg
32
+ end
33
+
34
+ # Get the error class for a given error_name
35
+ def self.error_class(error_name)
36
+ if AWS_TO_RUBY_ERROR_MAP.include? error_name
37
+ return AWS_TO_RUBY_ERROR_MAP[error_name]
38
+ end
39
+
40
+ constant = error_class_constant(error_name)
41
+ if error_const_set?(constant)
42
+ # modeled error class exist
43
+ # set code attribute
44
+ const_get(constant)
45
+
46
+ else
47
+ add_error_constant(constant)
48
+ end
49
+ end
50
+
51
+ # Convert an error code to an error class name/constant.
52
+ # This requires filtering non-safe characters from the constant
53
+ # name and ensuring it begins with an uppercase letter.
54
+ def self.error_class_constant(error_name)
55
+ error_name.to_s.gsub(/AWS_ERROR_/, '').split('_').map(&:capitalize).join
56
+ end
57
+
58
+ def self.add_error_constant(constant)
59
+ @const_set_mutex.synchronize do
60
+ # Ensure the const was not defined while blocked by the mutex
61
+ if error_const_set?(constant)
62
+ const_get(constant)
63
+ else
64
+ error_class = Class.new(Aws::Crt::Error)
65
+ const_set(constant, error_class)
66
+ end
67
+ end
68
+ end
69
+
70
+ def self.error_const_set?(constant)
71
+ # Purposefully not using #const_defined? as that method returns true
72
+ # for constants not defined directly in the current module.
73
+ constants.include?(constant.to_sym)
74
+ end
75
+ end
76
+ end
77
+ end