xoodyak 0.1.0 → 0.1.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: '087e6888550b824a43b269965b1066bd4daad3d1942cc517ced8435ffcfaa21b'
4
- data.tar.gz: 0cabd3ab1dfddae09c63de3040479e365e11c10726d9a3a484f7983927080173
3
+ metadata.gz: 13318d9467b578f9911c3e98d62aee09ac97ed77eb5d115d1c649f5374746ca7
4
+ data.tar.gz: 13e069990c466db0e03e21fce0e846a0fae3bd2e81b02244d4f3cb849b5e4230
5
5
  SHA512:
6
- metadata.gz: ea9b1f41888eef78c4ca2e960988f7f04cc418386b2883f0cf4653be7a699b7eef0eb5d44c9b072fd0a9dbf2340bf6d5082ceb16c7f5582c7bf502bc0a90c0cb
7
- data.tar.gz: 1c0a4f756035ff03478a7031c40fd505d03f7c32fb02e0e5e755ac7ed872c587dafe2b71f161cd308907c4fa183769553ede8bc3bf615fdee91c12303999bab1
6
+ metadata.gz: 606a31bad9694805482c9a7619678e006a8fef6c3b914409db491aa0614d32ffd744da90c8b8ee612da26bf7282d118e5a1867a3700cd31fa37f5d4519c83714
7
+ data.tar.gz: 613e1262ebd6bd9e3bd0ce30ca1c6b79d6aeb494b79d5f447d56c8d30e8d663dd7f6e4aadf24dc1fe64148496ba58575e2439c51763e1eb578f58dd1a6f55a4b
data/README.md CHANGED
@@ -157,12 +157,12 @@ key = "my-secure-key-16"
157
157
  nonce = SecureRandom.bytes(16) # Nonces must be unique for each encryption!
158
158
 
159
159
  # Encrypt with Associated Data
160
- alice = Xoodyak.new(key, nonce)
160
+ alice = Xoodyak.new(key, nonce: nonce)
161
161
  alice.absorb("Associated Data (unencrypted header)")
162
162
  ciphertext_with_tag = alice.aead_encrypt("confidential message")
163
163
 
164
164
  # Decrypt and Verify
165
- bob = Xoodyak.new(key, nonce)
165
+ bob = Xoodyak.new(key, nonce: nonce)
166
166
  bob.absorb("Associated Data (unencrypted header)") # Must match Alice's AD
167
167
 
168
168
  begin
@@ -186,12 +186,12 @@ key = "my-secure-key-16"
186
186
  nonce = SecureRandom.bytes(16)
187
187
 
188
188
  # Encrypt
189
- alice = Xoodyak.new(key, nonce)
189
+ alice = Xoodyak.new(key, nonce: nonce)
190
190
  alice.absorb("metadata")
191
191
  ciphertext, tag = alice.aead_encrypt_detached("confidential message")
192
192
 
193
193
  # Decrypt and Verify
194
- bob = Xoodyak.new(key, nonce)
194
+ bob = Xoodyak.new(key, nonce: nonce)
195
195
  bob.absorb("metadata")
196
196
 
197
197
  begin
@@ -212,7 +212,7 @@ Xoodyak supports initializing the keyed state with a variety of optional paramet
212
212
 
213
213
  ```ruby
214
214
  # Initialize with key, nonce, key_id, and counter
215
- xoodyak = Xoodyak.new(key, nonce, key_id, counter)
215
+ xoodyak = Xoodyak.new(key, nonce: nonce, key_id: key_id, counter: counter)
216
216
  ```
217
217
 
218
218
  > [!WARNING]
@@ -248,8 +248,8 @@ require 'securerandom'
248
248
  key = "session-key-1234"
249
249
  nonce = SecureRandom.bytes(16)
250
250
 
251
- alice = Xoodyak.new(key, nonce)
252
- bob = Xoodyak.new(key, nonce)
251
+ alice = Xoodyak.new(key, nonce: nonce)
252
+ bob = Xoodyak.new(key, nonce: nonce)
253
253
 
254
254
  # Alice sends first message
255
255
  ct1 = alice.encrypt("Message 1")
@@ -294,7 +294,7 @@ puts checkpoint.squeeze(16).unpack1("H*") # Squeezes based on "initial setup d
294
294
 
295
295
  | Method | Signature | Mode | Description |
296
296
  | :--- | :--- | :--- | :--- |
297
- | `initialize` | `(key=nil, nonce=nil, key_id=nil, counter=nil)` | Any | Creates a Xoodyak instance. Enters keyed mode if a key is provided. |
297
+ | `initialize` | `(key=nil, nonce: nil, key_id: nil, counter: nil)` | Any | Creates a Xoodyak instance. Enters keyed mode if a key is provided. |
298
298
  | `absorb` | `(bin: String) -> void` | Any | Absorbs binary data into the state. |
299
299
  | `squeeze` | `(len: Integer) -> String` | Any | Squeezes `len` bytes from the state. |
300
300
  | `squeeze_key` | `(len: Integer) -> String` | Any | Squeezes `len` key bytes from the state. |
@@ -1,6 +1,6 @@
1
1
  [package]
2
- name = "xoodyak"
3
- version = "0.1.0"
2
+ name = "xoodyakrb"
3
+ version = "0.1.1"
4
4
  edition = "2021"
5
5
  publish = false
6
6
 
@@ -18,6 +18,6 @@ digest_use_rb_ext_resolve_symbol = try_compile(<<~C)
18
18
  C
19
19
  puts("digest_use_rb_ext_resolve_symbol=#{digest_use_rb_ext_resolve_symbol}")
20
20
 
21
- create_rust_makefile("xoodyak/xoodyak") do |r|
21
+ create_rust_makefile("xoodyak/xoodyakrb") do |r|
22
22
  r.extra_rustflags = ["--cfg digest_use_rb_ext_resolve_symbol"] if digest_use_rb_ext_resolve_symbol
23
23
  end
@@ -3,7 +3,9 @@ use std::ffi::{c_int, c_uchar, c_void};
3
3
  use std::mem::MaybeUninit;
4
4
  use std::os::raw::c_char;
5
5
  use magnus::{
6
- prelude::*, scan_args::scan_args, Error, ExceptionClass, RString, Ruby, Value,
6
+ prelude::*,
7
+ scan_args::{get_kwargs, scan_args},
8
+ Error, ExceptionClass, RHash, RString, Ruby, Value,
7
9
  };
8
10
  use rb_sys::{VALUE, size_t};
9
11
  use xoodyak::{XoodyakHash, XoodyakKeyed, XoodyakCommon, XoodyakError, XOODYAK_AUTH_TAG_BYTES};
@@ -242,8 +244,14 @@ impl magnus::DataTypeFunctions for Xoodyak {}
242
244
 
243
245
  impl Xoodyak {
244
246
  fn initialize(rb_self: magnus::typed_data::Obj<Self>, args: &[Value]) -> Result<(), Error> {
245
- let args = scan_args::<(), (Option<Option<RString>>, Option<Option<RString>>, Option<Option<RString>>, Option<Option<RString>>), (), (), (), ()>(args)?;
246
- let (key, nonce, key_id, counter) = args.optional;
247
+ let args = scan_args::<(), (Option<Option<RString>>,), (), (), RHash, ()>(args)?;
248
+ let (key,) = args.optional;
249
+ let kw = get_kwargs::<_, (), (Option<Option<RString>>, Option<Option<RString>>, Option<Option<RString>>), ()>(
250
+ args.keywords,
251
+ &[],
252
+ &["nonce", "key_id", "counter"],
253
+ )?;
254
+ let (nonce, key_id, counter) = kw.optional;
247
255
  let key = key.flatten();
248
256
  let nonce = nonce.flatten();
249
257
  let key_id = key_id.flatten();
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Xoodyak
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/xoodyak.rb CHANGED
@@ -13,12 +13,12 @@ require_relative "xoodyak/version"
13
13
 
14
14
  begin
15
15
  RUBY_VERSION =~ /(\d+\.\d+)/
16
- require "xoodyak/#{Regexp.last_match(1)}/xoodyak"
16
+ require "xoodyak/#{Regexp.last_match(1)}/xoodyakrb"
17
17
  rescue LoadError
18
18
  begin
19
- require_relative "xoodyak/xoodyak"
19
+ require_relative "xoodyak/xoodyakrb"
20
20
  rescue LoadError
21
- require "xoodyak/xoodyak"
21
+ require "xoodyak/xoodyakrb"
22
22
  end
23
23
  end
24
24
 
data/sig/xoodyak.rbs CHANGED
@@ -19,7 +19,7 @@ class Xoodyak
19
19
  class Digest < ::Digest::Base
20
20
  end
21
21
 
22
- def initialize: (?String? key, ?String? nonce, ?String? key_id, ?String? counter) -> void
22
+ def initialize: (?String? key, ?nonce: String?, ?key_id: String?, ?counter: String?) -> void
23
23
  def initialize_copy: (Xoodyak other) -> void
24
24
  def absorb: (String bin) -> void
25
25
  def squeeze: (Integer len) -> String
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xoodyak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarun Rattanasiri