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 +7 -0
- data/CHANGELOG.md +17 -0
- data/LICENSE.txt +202 -0
- data/VERSION +1 -0
- data/bin/arm64/libaws-crt-ffi.dylib +0 -0
- data/lib/aws-crt/auth/credentials.rb +78 -0
- data/lib/aws-crt/auth/signable.rb +20 -0
- data/lib/aws-crt/auth/signer.rb +50 -0
- data/lib/aws-crt/auth/signing_config.rb +122 -0
- data/lib/aws-crt/auth/static_credentials_provider.rb +68 -0
- data/lib/aws-crt/checksums/crc.rb +24 -0
- data/lib/aws-crt/errors.rb +77 -0
- data/lib/aws-crt/http/headers.rb +32 -0
- data/lib/aws-crt/http/message.rb +54 -0
- data/lib/aws-crt/io/event_loop_group.rb +51 -0
- data/lib/aws-crt/managed_native.rb +87 -0
- data/lib/aws-crt/native.rb +222 -0
- data/lib/aws-crt/platforms.rb +72 -0
- data/lib/aws-crt/string_blob.rb +42 -0
- data/lib/aws-crt.rb +29 -0
- metadata +91 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Crt
|
5
|
+
# High level Ruby abstractions for CRT HTTP functionality
|
6
|
+
module Http
|
7
|
+
# HTTP Headers
|
8
|
+
class Headers
|
9
|
+
include Aws::Crt::ManagedNative
|
10
|
+
native_destroy Aws::Crt::Native.method(
|
11
|
+
:http_headers_release
|
12
|
+
)
|
13
|
+
|
14
|
+
def initialize(headers = {})
|
15
|
+
blob = StringBlob.encode(headers.flatten)
|
16
|
+
blob_ptr = FFI::MemoryPointer.new(:char, blob.length)
|
17
|
+
blob_ptr.write_array_of_char(blob)
|
18
|
+
|
19
|
+
manage_native do
|
20
|
+
Aws::Crt::Native.http_headers_new_from_blob(blob_ptr, blob.length)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_blob_strings
|
25
|
+
buf_out = Aws::Crt::Native::CrtBuf.new
|
26
|
+
Aws::Crt::Native.http_headers_to_blob(native, buf_out)
|
27
|
+
StringBlob.decode(buf_out.to_blob)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Crt
|
5
|
+
# High level Ruby abstractions for CRT HTTP functionality
|
6
|
+
module Http
|
7
|
+
# HTTP Message (request)
|
8
|
+
class Message
|
9
|
+
include Aws::Crt::ManagedNative
|
10
|
+
native_destroy Aws::Crt::Native.method(
|
11
|
+
:http_message_release
|
12
|
+
)
|
13
|
+
|
14
|
+
def initialize(method, path, headers = {})
|
15
|
+
strings = [method, path] +
|
16
|
+
headers.flatten
|
17
|
+
blob = StringBlob.encode(strings)
|
18
|
+
blob_ptr = FFI::MemoryPointer.new(:char, blob.length)
|
19
|
+
blob_ptr.write_array_of_char(blob)
|
20
|
+
|
21
|
+
manage_native do
|
22
|
+
Aws::Crt::Native.http_message_new_from_blob(blob_ptr, blob.length)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_blob_strings
|
27
|
+
buf_out = Aws::Crt::Native::CrtBuf.new
|
28
|
+
Aws::Crt::Native.http_message_to_blob(native, buf_out)
|
29
|
+
StringBlob.decode(buf_out.to_blob)
|
30
|
+
end
|
31
|
+
|
32
|
+
def headers
|
33
|
+
blob_strings = to_blob_strings
|
34
|
+
# blob_strings must have at least 2 element and must have
|
35
|
+
# pairs of header/values
|
36
|
+
if blob_strings.length < 2 ||
|
37
|
+
blob_strings.length.odd?
|
38
|
+
raise Aws::Crt::Errors::Error,
|
39
|
+
'Invalid blob_string for HTTP Message'
|
40
|
+
end
|
41
|
+
blob_strings[2..blob_strings.length].each_slice(2).to_h
|
42
|
+
end
|
43
|
+
|
44
|
+
def method
|
45
|
+
to_blob_strings[0]
|
46
|
+
end
|
47
|
+
|
48
|
+
def path
|
49
|
+
to_blob_strings[1]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Crt
|
5
|
+
# High level Ruby abstractions for CRT IO functionality
|
6
|
+
module IO
|
7
|
+
# Options for an EventLoopGroup
|
8
|
+
class EventLoopGroupOptions
|
9
|
+
include Aws::Crt::ManagedNative
|
10
|
+
native_destroy Aws::Crt::Native.method(
|
11
|
+
:event_loop_group_options_release
|
12
|
+
)
|
13
|
+
|
14
|
+
def initialize(max_threads = nil)
|
15
|
+
unless max_threads.nil? ||
|
16
|
+
(max_threads.is_a?(Integer) && max_threads.positive?)
|
17
|
+
raise ArgumentError, 'max_threads must be nil or positive Integer'
|
18
|
+
end
|
19
|
+
|
20
|
+
# Ruby uses nil to request default values, native code uses 0
|
21
|
+
max_threads = 0 if max_threads.nil?
|
22
|
+
|
23
|
+
manage_native do
|
24
|
+
Aws::Crt::Native.event_loop_group_options_new
|
25
|
+
end
|
26
|
+
|
27
|
+
Aws::Crt::Native.event_loop_group_options_set_max_threads(@native,
|
28
|
+
max_threads)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# A collection of event-loops.
|
33
|
+
# An event-loop is a thread for doing async work, such as I/O.
|
34
|
+
# Classes that need to do async work will ask the EventLoopGroup
|
35
|
+
# for an event-loop to use.
|
36
|
+
class EventLoopGroup
|
37
|
+
include Aws::Crt::ManagedNative
|
38
|
+
native_destroy Aws::Crt::Native.method(:event_loop_group_release)
|
39
|
+
|
40
|
+
def initialize(max_threads = nil)
|
41
|
+
@options = EventLoopGroupOptions.new(max_threads)
|
42
|
+
|
43
|
+
manage_native do
|
44
|
+
Aws::Crt::Native.event_loop_group_new(@options.native)
|
45
|
+
end
|
46
|
+
Aws::Crt::Native.event_loop_group_acquire(@native)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Crt
|
5
|
+
# A mixin module for generic managed native functionality
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# class C
|
9
|
+
# include Aws::Crt::ManagedNative
|
10
|
+
# native_destroy Aws::Crt::Native.method(:test_struct_destroy)
|
11
|
+
#
|
12
|
+
# def initialize
|
13
|
+
# manage_native { Aws::Crt::Native::test_struct_new() }
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def use_native
|
17
|
+
# Aws::Crt::Native::test_method(native) #use that getter for native
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
module ManagedNative
|
21
|
+
def self.included(sub_class)
|
22
|
+
sub_class.extend(ClassMethods)
|
23
|
+
end
|
24
|
+
|
25
|
+
# expects a block that returns a :pointer to the native resource
|
26
|
+
# that this class manages
|
27
|
+
def manage_native(&block)
|
28
|
+
# check that a destructor has been registered
|
29
|
+
unless self.class.instance_variable_get('@destructor')
|
30
|
+
raise 'No native destructor registered. use native_destroy to ' \
|
31
|
+
'set the method used to cleanup the native object this ' \
|
32
|
+
'class manages.'
|
33
|
+
end
|
34
|
+
native = block.call
|
35
|
+
@native = FFI::AutoPointer.new(native, self.class.method(:on_release))
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param [Boolean] safe (true) - raise an exception if the native object
|
39
|
+
# is not set (has been freed or never created)
|
40
|
+
# @return [FFI:Pointer]
|
41
|
+
def native(safe: true)
|
42
|
+
raise '@native is unset or has been freed.' if safe && !@native
|
43
|
+
|
44
|
+
@native
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Boolean]
|
48
|
+
def native_set?
|
49
|
+
!!@native
|
50
|
+
end
|
51
|
+
|
52
|
+
# Immediately release this instance's attachment to the underlying
|
53
|
+
# resources, without waiting for the garbage collector.
|
54
|
+
# Note that underlying resources will remain alive until nothing
|
55
|
+
# else is using them.
|
56
|
+
def release
|
57
|
+
return unless @native
|
58
|
+
|
59
|
+
@native.free
|
60
|
+
@native = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
# ClassMethods for ManagedNative
|
64
|
+
module ClassMethods
|
65
|
+
# Register the method used to cleanup the native object this class
|
66
|
+
# manages. Must be a method, use object.method(:method_name).
|
67
|
+
#
|
68
|
+
# Example:
|
69
|
+
# native_destroy Aws::Crt::Native.method(:test_release)
|
70
|
+
def native_destroy(destructor)
|
71
|
+
unless destructor.is_a?(Method)
|
72
|
+
raise ArgumentError,
|
73
|
+
'destructor must be a Method. ' \
|
74
|
+
'Use object.method(:method_name)'
|
75
|
+
end
|
76
|
+
@destructor = destructor
|
77
|
+
end
|
78
|
+
|
79
|
+
# Do not call directly
|
80
|
+
# method passed to FFI Autopointer to call the destructor
|
81
|
+
def on_release(native)
|
82
|
+
@destructor.call(native)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ffi'
|
4
|
+
module Aws
|
5
|
+
module Crt
|
6
|
+
# FFI Bindings to native CRT functions
|
7
|
+
module Native
|
8
|
+
extend FFI::Library
|
9
|
+
|
10
|
+
ffi_lib [crt_bin_path(local_platform), 'libaws-crt-ffi']
|
11
|
+
|
12
|
+
# Warning, when used as an output structure
|
13
|
+
# the memory in ptr needs to be manually destructed!
|
14
|
+
class CrtBuf < FFI::Struct
|
15
|
+
layout :ptr, :pointer,
|
16
|
+
:len, :size_t
|
17
|
+
|
18
|
+
def to_blob
|
19
|
+
return unless (self[:len]).positive? && !(self[:ptr]).null?
|
20
|
+
|
21
|
+
self[:ptr].read_array_of_char(self[:len])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Managed PropertyList Struct (for outputs)
|
26
|
+
class PropertyList < FFI::ManagedStruct
|
27
|
+
layout :len, :size_t,
|
28
|
+
:names, :pointer,
|
29
|
+
:values, :pointer
|
30
|
+
|
31
|
+
def props
|
32
|
+
return nil if to_ptr.null?
|
33
|
+
|
34
|
+
return {} unless (self[:len]).positive?
|
35
|
+
|
36
|
+
out = {}
|
37
|
+
names_p = self[:names].get_array_of_pointer(0, self[:len])
|
38
|
+
values_p = self[:values].get_array_of_pointer(0, self[:len])
|
39
|
+
names_p.zip(values_p).each do |name_p, value_p|
|
40
|
+
out[name_p.read_string.dup] = value_p.read_string.dup
|
41
|
+
end
|
42
|
+
out
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.release(ptr)
|
46
|
+
Aws::Crt::Native.aws_crt_property_list_release(ptr)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Given a ruby hash (string -> string), return two native arrays:
|
51
|
+
# char** (:pointer) AND a list of all of the FFI::MemoryPointers
|
52
|
+
# that must be kept around to avoid GC
|
53
|
+
def self.hash_to_native_arrays(hash)
|
54
|
+
key_array, keys_p = array_to_native(hash.keys)
|
55
|
+
value_array, values_p = array_to_native(hash.values)
|
56
|
+
[key_array, value_array, keys_p + values_p]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Given a ruby array of strings, return a native array: char** and
|
60
|
+
# the FFI::MemoryPointers (these need to be pined for the length the
|
61
|
+
# native memory will be used to avoid GC)
|
62
|
+
def self.array_to_native(array)
|
63
|
+
native = FFI::MemoryPointer.new(:pointer, array.size)
|
64
|
+
pointers = array.map do |s|
|
65
|
+
FFI::MemoryPointer.from_string(s.to_s)
|
66
|
+
end
|
67
|
+
native.write_array_of_pointer(pointers)
|
68
|
+
[native, pointers]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Extends FFI::attach_function
|
72
|
+
#
|
73
|
+
# 1. Allows us to only supply the aws_crt C name and removes
|
74
|
+
# the aws_crt.
|
75
|
+
# 2. Wraps the call in an error-raise checker (unless options[:raise]
|
76
|
+
# = false)
|
77
|
+
# 3. Creates a bang method that does not do automatic error checking.
|
78
|
+
def self.attach_function(c_name, params, returns, options = {})
|
79
|
+
ruby_name = c_name.to_s.sub(/aws_crt_/, '').to_sym
|
80
|
+
raise_errors = options.fetch(:raise, true)
|
81
|
+
options.delete(:raise)
|
82
|
+
unless raise_errors
|
83
|
+
return super(ruby_name, c_name, params, returns, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
bang_name = "#{ruby_name}!"
|
87
|
+
|
88
|
+
super(ruby_name, c_name, params, returns, options)
|
89
|
+
alias_method(bang_name, ruby_name)
|
90
|
+
|
91
|
+
define_method(ruby_name) do |*args, &block|
|
92
|
+
res = public_send(bang_name, *args, &block)
|
93
|
+
# functions that return void cannot fail
|
94
|
+
return unless res
|
95
|
+
|
96
|
+
# for functions that return int, non-zero indicates failure
|
97
|
+
Errors.raise_last_error if res.is_a?(Integer) && res != 0
|
98
|
+
|
99
|
+
# for functions that return pointer, NULL indicates failure
|
100
|
+
Errors.raise_last_error if res.is_a?(FFI::Pointer) && res.null?
|
101
|
+
|
102
|
+
res
|
103
|
+
end
|
104
|
+
|
105
|
+
module_function ruby_name
|
106
|
+
module_function bang_name
|
107
|
+
end
|
108
|
+
|
109
|
+
# Core API
|
110
|
+
attach_function :aws_crt_init, [], :void, raise: false
|
111
|
+
attach_function :aws_crt_clean_up, [], :void
|
112
|
+
attach_function :aws_crt_last_error, [], :int, raise: false
|
113
|
+
attach_function :aws_crt_error_str, [:int], :string, raise: false
|
114
|
+
attach_function :aws_crt_error_name, [:int], :string, raise: false
|
115
|
+
attach_function :aws_crt_error_debug_str, [:int], :string, raise: false
|
116
|
+
attach_function :aws_crt_reset_error, [], :void, raise: false
|
117
|
+
attach_function :aws_crt_thread_join_all, [:uint64], :int
|
118
|
+
|
119
|
+
# Core Memory Management
|
120
|
+
attach_function :aws_crt_mem_release, [:pointer], :void, raise: false
|
121
|
+
attach_function :aws_crt_mem_bytes, [], :uint64, raise: false
|
122
|
+
attach_function :aws_crt_mem_count, [], :uint64, raise: false
|
123
|
+
attach_function :aws_crt_mem_dump, [], :void, raise: false
|
124
|
+
|
125
|
+
typedef :pointer, :blob
|
126
|
+
|
127
|
+
# IO API
|
128
|
+
typedef :pointer, :event_loop_group_options_ptr
|
129
|
+
attach_function :aws_crt_event_loop_group_options_new, [], :event_loop_group_options_ptr
|
130
|
+
attach_function :aws_crt_event_loop_group_options_release, [:event_loop_group_options_ptr], :void
|
131
|
+
attach_function :aws_crt_event_loop_group_options_set_max_threads, %i[event_loop_group_options_ptr uint16], :void
|
132
|
+
|
133
|
+
typedef :pointer, :event_loop_group_ptr
|
134
|
+
attach_function :aws_crt_event_loop_group_new, [:event_loop_group_options_ptr], :pointer
|
135
|
+
attach_function :aws_crt_event_loop_group_acquire, [:event_loop_group_ptr], :event_loop_group_ptr
|
136
|
+
attach_function :aws_crt_event_loop_group_release, [:event_loop_group_ptr], :void
|
137
|
+
|
138
|
+
# HTTP API
|
139
|
+
typedef :pointer, :headers_ptr
|
140
|
+
attach_function :aws_crt_http_headers_new_from_blob, %i[blob size_t], :headers_ptr
|
141
|
+
attach_function :aws_crt_http_headers_to_blob, [:headers_ptr, CrtBuf], :void
|
142
|
+
attach_function :aws_crt_http_headers_release, [:headers_ptr], :void
|
143
|
+
|
144
|
+
typedef :pointer, :http_message_ptr
|
145
|
+
attach_function :aws_crt_http_message_new_from_blob, %i[blob size_t], :http_message_ptr
|
146
|
+
attach_function :aws_crt_http_message_to_blob, [:http_message_ptr, CrtBuf], :void
|
147
|
+
attach_function :aws_crt_http_message_release, [:http_message_ptr], :void
|
148
|
+
|
149
|
+
# Auth API
|
150
|
+
typedef :pointer, :credentials_options_ptr
|
151
|
+
attach_function :aws_crt_credentials_options_new, [], :credentials_options_ptr
|
152
|
+
attach_function :aws_crt_credentials_options_release, [:credentials_options_ptr], :void
|
153
|
+
attach_function :aws_crt_credentials_options_set_access_key_id, %i[credentials_options_ptr string size_t], :void
|
154
|
+
attach_function :aws_crt_credentials_options_set_secret_access_key, %i[credentials_options_ptr string size_t], :void
|
155
|
+
attach_function :aws_crt_credentials_options_set_session_token, %i[credentials_options_ptr string size_t], :void
|
156
|
+
attach_function :aws_crt_credentials_options_set_expiration_timepoint_seconds, %i[credentials_options_ptr uint64], :void
|
157
|
+
|
158
|
+
typedef :pointer, :credentials_ptr
|
159
|
+
attach_function :aws_crt_credentials_new, [:credentials_options_ptr], :credentials_ptr
|
160
|
+
attach_function :aws_crt_credentials_acquire, [:credentials_ptr], :credentials_ptr
|
161
|
+
attach_function :aws_crt_credentials_release, [:credentials_ptr], :void
|
162
|
+
|
163
|
+
typedef :pointer, :credentials_provider_ptr
|
164
|
+
attach_function :aws_crt_credentials_provider_acquire, [:credentials_provider_ptr], :credentials_provider_ptr
|
165
|
+
attach_function :aws_crt_credentials_provider_release, [:credentials_provider_ptr], :void
|
166
|
+
|
167
|
+
typedef :pointer, :static_cred_provider_options_ptr
|
168
|
+
attach_function :aws_crt_credentials_provider_static_options_new, [], :static_cred_provider_options_ptr
|
169
|
+
attach_function :aws_crt_credentials_provider_static_options_release, [:static_cred_provider_options_ptr], :void
|
170
|
+
attach_function :aws_crt_credentials_provider_static_options_set_access_key_id, %i[static_cred_provider_options_ptr string size_t], :void
|
171
|
+
attach_function :aws_crt_credentials_provider_static_options_set_secret_access_key, %i[static_cred_provider_options_ptr string size_t], :void
|
172
|
+
attach_function :aws_crt_credentials_provider_static_options_set_session_token, %i[static_cred_provider_options_ptr string size_t], :void
|
173
|
+
|
174
|
+
attach_function :aws_crt_credentials_provider_static_new, [:static_cred_provider_options_ptr], :credentials_provider_ptr
|
175
|
+
|
176
|
+
enum :signing_algorithm, %i[sigv4 sigv4a]
|
177
|
+
enum :signature_type, %i[
|
178
|
+
http_request_headers http_request_query_params
|
179
|
+
http_request_chunk http_request_event
|
180
|
+
canonical_request_headers canonical_request_query_params
|
181
|
+
]
|
182
|
+
enum :signed_body_header_type, %i[sbht_none sbht_content_sha256]
|
183
|
+
|
184
|
+
typedef :pointer, :signing_config_ptr
|
185
|
+
callback :should_sign_header_fn, %i[pointer size_t pointer], :bool
|
186
|
+
attach_function :aws_crt_signing_config_aws_new, [], :signing_config_ptr
|
187
|
+
attach_function :aws_crt_signing_config_aws_release, [:signing_config_ptr], :void
|
188
|
+
attach_function :aws_crt_signing_config_aws_validate, [:signing_config_ptr], :bool
|
189
|
+
attach_function :aws_crt_signing_config_aws_set_algorithm, %i[signing_config_ptr signing_algorithm], :void
|
190
|
+
attach_function :aws_crt_signing_config_aws_set_signature_type, %i[signing_config_ptr signature_type], :void
|
191
|
+
attach_function :aws_crt_signing_config_aws_set_credentials_provider, %i[signing_config_ptr credentials_provider_ptr], :void
|
192
|
+
attach_function :aws_crt_signing_config_aws_set_region, %i[signing_config_ptr string size_t], :void
|
193
|
+
attach_function :aws_crt_signing_config_aws_set_service, %i[signing_config_ptr string size_t], :void
|
194
|
+
attach_function :aws_crt_signing_config_aws_set_use_double_uri_encode, %i[signing_config_ptr bool], :void
|
195
|
+
attach_function :aws_crt_signing_config_aws_set_should_normalize_uri_path, %i[signing_config_ptr bool], :void
|
196
|
+
attach_function :aws_crt_signing_config_aws_set_omit_session_token, %i[signing_config_ptr bool], :void
|
197
|
+
attach_function :aws_crt_signing_config_aws_set_signed_body_value, %i[signing_config_ptr string size_t], :void
|
198
|
+
attach_function :aws_crt_signing_config_aws_set_signed_body_header_type, %i[signing_config_ptr signed_body_header_type], :void
|
199
|
+
attach_function :aws_crt_signing_config_aws_set_expiration_in_seconds, %i[signing_config_ptr uint64], :void
|
200
|
+
attach_function :aws_crt_signing_config_aws_set_date, %i[signing_config_ptr uint64], :void
|
201
|
+
attach_function :aws_crt_signing_config_aws_set_should_sign_header_fn, %i[signing_config_ptr should_sign_header_fn], :void
|
202
|
+
|
203
|
+
typedef :pointer, :signable_ptr
|
204
|
+
attach_function :aws_crt_signable_new_from_http_request, [:http_message_ptr], :signable_ptr
|
205
|
+
attach_function :aws_crt_signable_release, [:signable_ptr], :void
|
206
|
+
|
207
|
+
typedef :pointer, :user_data_ptr
|
208
|
+
typedef :pointer, :signing_result_ptr
|
209
|
+
|
210
|
+
callback :signing_complete_fn, %i[signing_result_ptr int user_data_ptr], :void
|
211
|
+
attach_function :aws_crt_sign_request_aws, %i[signable_ptr signing_config_ptr signing_complete_fn user_data_ptr], :int
|
212
|
+
attach_function :aws_crt_signing_result_apply_to_http_request, %i[signing_result_ptr http_message_ptr], :int
|
213
|
+
|
214
|
+
# Checksums
|
215
|
+
attach_function :aws_crt_crc32, %i[pointer size_t uint32], :uint32, raise: false
|
216
|
+
attach_function :aws_crt_crc32c, %i[pointer size_t uint32], :uint32, raise: false
|
217
|
+
|
218
|
+
# Internal testing API
|
219
|
+
attach_function :aws_crt_test_error, [:int], :int
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Maps OS name to crt binary name.
|
4
|
+
OS_BINARIES = {
|
5
|
+
'darwin' => 'libaws-crt-ffi.dylib',
|
6
|
+
'linux' => 'libaws-crt-ffi.so',
|
7
|
+
'mingw32' => 'aws-crt-ffi.dll'
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
DEFAULT_BINARY = 'libaws-crt-ffi.so'
|
11
|
+
|
12
|
+
# @return [Gem::Platform] similar to Gem::Platform.local but will return
|
13
|
+
# host os/cpu for Jruby
|
14
|
+
def local_platform
|
15
|
+
Gem::Platform.new(host_string)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Gem::Platform] return Gem::Platform for host os with target cpu
|
19
|
+
def target_platform(cpu)
|
20
|
+
Gem::Platform.new(target_string(cpu))
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [String] return the file name for the CRT library for the platform
|
24
|
+
def crt_bin_name(platform)
|
25
|
+
OS_BINARIES[platform.os] || DEFAULT_BINARY
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [String] return the directory of the CRT library for the platform
|
29
|
+
def crt_bin_dir(platform)
|
30
|
+
File.expand_path("../../bin/#{platform.cpu}", File.dirname(__FILE__))
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [String] return the path to the CRT library for the platform
|
34
|
+
def crt_bin_path(platform)
|
35
|
+
File.expand_path(crt_bin_name(platform), crt_bin_dir(platform))
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [String] generate a string that can be used with Gem::Platform
|
39
|
+
def host_string
|
40
|
+
target_string(host_cpu)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [String] generate a string that can be used with Gem::Platform
|
44
|
+
def target_string(cpu)
|
45
|
+
"#{cpu}-#{host_os}"
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [String] host cpu, even on jruby
|
49
|
+
def host_cpu
|
50
|
+
case RbConfig::CONFIG['host_cpu']
|
51
|
+
when /86_64/
|
52
|
+
'x86_64'
|
53
|
+
when /86/
|
54
|
+
'x86'
|
55
|
+
else
|
56
|
+
RbConfig::CONFIG['host_cpu']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String] host os, even on jruby
|
61
|
+
def host_os
|
62
|
+
case RbConfig::CONFIG['host_os']
|
63
|
+
when /darwin/
|
64
|
+
'darwin'
|
65
|
+
when /linux/
|
66
|
+
'linux'
|
67
|
+
when /mingw|mswin/
|
68
|
+
'mingw32'
|
69
|
+
else
|
70
|
+
RbConfig::CONFIG['host_os']
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
module Aws
|
6
|
+
module Crt
|
7
|
+
# module for CRT Blob utility methods
|
8
|
+
# CRT encodes lists of strings as [length, str*]
|
9
|
+
# using null padded, unsigned long
|
10
|
+
module StringBlob
|
11
|
+
# Encode an array of strings into
|
12
|
+
# a buffer (blob)
|
13
|
+
# @param strings [Array<String>]
|
14
|
+
# @return buffer (Array<char>)
|
15
|
+
def self.encode(strings)
|
16
|
+
buffer = StringIO.new
|
17
|
+
strings.each do |s|
|
18
|
+
e = s.to_s.unpack('c*')
|
19
|
+
buffer << [e.length].pack('N')
|
20
|
+
buffer << (e).pack('c*')
|
21
|
+
end
|
22
|
+
buffer.string.unpack('c*')
|
23
|
+
end
|
24
|
+
|
25
|
+
# Decode a blob (StringBlob)/Buffer into
|
26
|
+
# an array of strings
|
27
|
+
# @param buffer - array of chars (buffer)
|
28
|
+
# @return strings
|
29
|
+
def self.decode(buffer)
|
30
|
+
strings = []
|
31
|
+
i = 0
|
32
|
+
while i < buffer.size
|
33
|
+
len = buffer[i, 4].pack('c*').unpack1('N')
|
34
|
+
strings << (buffer[i + 4, len].pack('c*'))
|
35
|
+
.force_encoding(Encoding::UTF_8)
|
36
|
+
i += len + 4
|
37
|
+
end
|
38
|
+
strings
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/aws-crt.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'aws-crt/platforms'
|
4
|
+
require_relative 'aws-crt/native'
|
5
|
+
require_relative 'aws-crt/errors'
|
6
|
+
require_relative 'aws-crt/managed_native'
|
7
|
+
require_relative 'aws-crt/string_blob'
|
8
|
+
|
9
|
+
require_relative 'aws-crt/io/event_loop_group'
|
10
|
+
require_relative 'aws-crt/http/headers'
|
11
|
+
require_relative 'aws-crt/http/message'
|
12
|
+
|
13
|
+
require_relative 'aws-crt/auth/credentials'
|
14
|
+
require_relative 'aws-crt/auth/static_credentials_provider'
|
15
|
+
require_relative 'aws-crt/auth/signing_config'
|
16
|
+
require_relative 'aws-crt/auth/signable'
|
17
|
+
require_relative 'aws-crt/auth/signer'
|
18
|
+
require_relative 'aws-crt/checksums/crc'
|
19
|
+
|
20
|
+
# Top level Amazon Web Services (AWS) namespace
|
21
|
+
module Aws
|
22
|
+
# Common runtime bindings
|
23
|
+
module Crt
|
24
|
+
GEM_VERSION = File.read(File.expand_path('../VERSION', __dir__)).strip
|
25
|
+
|
26
|
+
# Ensure native init() is called when gem loads
|
27
|
+
Aws::Crt::Native.init
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-crt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: arm64-darwin
|
6
|
+
authors:
|
7
|
+
- Amazon Web Services
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- CHANGELOG.md
|
48
|
+
- LICENSE.txt
|
49
|
+
- VERSION
|
50
|
+
- bin/arm64/libaws-crt-ffi.dylib
|
51
|
+
- lib/aws-crt.rb
|
52
|
+
- lib/aws-crt/auth/credentials.rb
|
53
|
+
- lib/aws-crt/auth/signable.rb
|
54
|
+
- lib/aws-crt/auth/signer.rb
|
55
|
+
- lib/aws-crt/auth/signing_config.rb
|
56
|
+
- lib/aws-crt/auth/static_credentials_provider.rb
|
57
|
+
- lib/aws-crt/checksums/crc.rb
|
58
|
+
- lib/aws-crt/errors.rb
|
59
|
+
- lib/aws-crt/http/headers.rb
|
60
|
+
- lib/aws-crt/http/message.rb
|
61
|
+
- lib/aws-crt/io/event_loop_group.rb
|
62
|
+
- lib/aws-crt/managed_native.rb
|
63
|
+
- lib/aws-crt/native.rb
|
64
|
+
- lib/aws-crt/platforms.rb
|
65
|
+
- lib/aws-crt/string_blob.rb
|
66
|
+
homepage: https://github.com/awslabs/aws-crt-ruby
|
67
|
+
licenses:
|
68
|
+
- Apache-2.0
|
69
|
+
metadata:
|
70
|
+
source_code_uri: https://github.com/awslabs/aws-crt-ruby/tree/main/gems/aws-crt
|
71
|
+
changelog_uri: https://github.com/awslabs/aws-crt-ruby/tree/main/gems/aws-crt/CHANGELOG.md
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '2.5'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.1.6
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: AWS SDK for Ruby - Common Run Time
|
91
|
+
test_files: []
|