Skip to content

Commit

Permalink
CRC64NVME support
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Sep 16, 2024
1 parent de55b41 commit 7807fba
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 23 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@
* [AWS Common Run Time](https://docs.aws.amazon.com/sdkref/latest/guide/common-runtime.html)

## Installation
AWS CRT bindings are in developer preview and are available from RubyGems as the `aws-crt` gem. You can install them by adding the `aws-crt`
gem to your Gemfile.

[Sigv4a](https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html)
is an extension to Sigv4 that allows signatures that are valid in more than one region.
Sigv4a is required to use some services/operations such as
[S3 Multi-Region Access Points](https://docs.aws.amazon.com/AmazonS3/latest/userguide/MultiRegionAccessPoints.html).
Currently sigv4a requires the [aws-crt](https://rubygems.org/gems/aws-crt/) gem and a version of the
[aws-sigv4](https://rubygems.org/gems/aws-sigv4/) gem built on top of aws-crt (at least version 1.5.0):
AWS CRT bindings are available from RubyGems as the `aws-crt` gem.

```ruby
gem 'aws-sdk-s3', '~> 1'
gem 'aws-sigv4', '~> 1' # must be at least 1.5.0
gem 'aws-crt'
gem 'aws-crt', '~> 0'
```

`aws-crt` currently provides fast checksum implementations for CRC32c and CRC64.

## Versioning

This project uses [semantic versioning](http://semver.org/). You can safely
Expand Down
12 changes: 9 additions & 3 deletions gems/aws-crt/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
Unreleased Changes
------------------

* Issue - update to the latest aws-crt-ffi.
* Feature - Support CRC64NVME checksums.

0.2.1 (2024-06-13)
------------------

* Issue - Update to the latest aws-crt-ffi.

0.2.0 (2023-11-28)
------------------

* Feature - support sigv4-s3express signing.
* Feature - Support sigv4-s3express signing.

0.1.9 (2023-10-16)
------------------
Expand All @@ -16,12 +21,13 @@ Unreleased Changes
0.1.8 (2023-03-28)
------------------

* Issue - fix `warning: method redefined` warnings.
* Issue - Fix `warning: method redefined` warnings.

0.1.7 (2023-02-03)
------------------

* Issue - Update to the latest aws-crt-ffi.
*
* Issue - Add support for overriding crt_bin_dir with `AWS_CRT_RUBY_BIN_DIR`.

0.1.6 (2022-08-12)
Expand Down
8 changes: 8 additions & 0 deletions gems/aws-crt/lib/aws-crt/checksums/crc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def self.crc32c(str, previous = 0)
previous
)
end

def self.crc64nvme(str, previous = 0)
Aws::Crt::Native.crc64nvme(
FFI::MemoryPointer.from_string(str),
str.size,
previous
)
end
end
end
end
1 change: 1 addition & 0 deletions gems/aws-crt/lib/aws-crt/native.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def self.attach_function(c_name, params, returns, options = {})
# Checksums
attach_function :aws_crt_crc32, %i[pointer size_t uint32], :uint32, raise: false
attach_function :aws_crt_crc32c, %i[pointer size_t uint32], :uint32, raise: false
attach_function :aws_crt_crc64nvme, %i[pointer size_t uint64], :uint64, raise: false

# Internal testing API
attach_function :aws_crt_test_error, [:int], :int
Expand Down
49 changes: 47 additions & 2 deletions gems/aws-crt/spec/checksums/crc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def int32_to_base64(num)
expect(output).to eq(0x91267E8A)
end

it 'works with values in one shot' do
it 'works with values iterated' do
output = 0
32.times do |i|
output = Aws::Crt::Checksums.crc32([i].pack('C*'), output)
Expand Down Expand Up @@ -96,7 +96,7 @@ def int32_to_base64(num)
expect(output).to eq(0x46DD794E)
end

it 'works with values in one shot' do
it 'works with values iterated' do
output = 0
32.times do |i|
output = Aws::Crt::Checksums.crc32c([i].pack('C*'), output)
Expand All @@ -116,4 +116,49 @@ def int32_to_base64(num)
skip 'Unable to allocate memory for crc32c huge buffer test'
end
end

describe 'crc64nvme' do
test_cases = [
{ str: '', expected: "AAAAAA==\n" },
{ str: 'abc', expected: "P8H66w==\n" },
{ str: 'Hello world', expected: "PzEq2w==\n" }
]
test_cases.each do |test_case|
it "produces the correct checksum for '#{test_case[:str]}'" do
checksum = int32_to_base64(Aws::Crt::Checksums.crc64nvme(test_case[:str]))
expect(checksum).to eq(test_case[:expected])
end
end

it 'works with zeros in one shot' do
output = Aws::Crt::Checksums.crc64nvme(ZERO_CHAR * 32)
expect(output).to eq(0xCF3473434D4ECF3B)
end

it 'works with zeros iterated' do
output = 0
32.times do
output = Aws::Crt::Checksums.crc64nvme(ZERO_CHAR, output)
end
expect(output).to eq(0xCF3473434D4ECF3B)
end

it 'works with values in one shot' do
buf = (0...32).to_a.pack('C*')
output = Aws::Crt::Checksums.crc64nvme(buf)
expect(output).to eq(0xB9D9D4A8492CBD7F)
end

it 'works with a large buffer' do
output = Aws::Crt::Checksums.crc64nvme(ZERO_CHAR * 25 * (2**20))
expect(output).to eq(0x5B6F5045463CA45E)
end

it 'works with a huge buffer' do
output = Aws::Crt::Checksums.crc64nvme(ZERO_CHAR * (INT_MAX + 5))
expect(output).to eq(0x2645C28052B1FBB0)
rescue NoMemoryError, RangeError
skip 'Unable to allocate memory for crc32c huge buffer test'
end
end
end
5 changes: 0 additions & 5 deletions gems/aws-crt/tasks/compile.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@ task :bin, [:cpu] do |_, args|
require_relative '../ext/compile'
compile_bin(args[:cpu])
end

desc 'Copies all binaries from the top level bin directory'
task 'bin:all' do
FileUtils.cp_r('bin/', 'gems/aws-crt', verbose: true)
end
2 changes: 1 addition & 1 deletion gems/aws-crt/tasks/gem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ task 'gem:aws-crt:pure-ruby' => :clean do
end

desc 'Build the aws-crt gem for jruby, bundling all currently built platforms'
task 'gem:aws-crt:jruby' => 'bin:all' do
task 'gem:aws-crt:jruby' do
require 'rubygems/package'
require 'fileutils'

Expand Down

0 comments on commit 7807fba

Please sign in to comment.