Skip to content

Commit

Permalink
Freeze JWE::Alg::AesKw strings to prevent warnings when using Ruby 3.4
Browse files Browse the repository at this point in the history
Co-authored-by: Étienne Barrié <[email protected]>
  • Loading branch information
larouxn and etiennebarrie committed Jan 7, 2025
1 parent eb0cbea commit 5a2962c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/jwe/alg/aes_kw.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'jwe/enc/cipher'

module JWE
Expand All @@ -8,13 +10,13 @@ module AesKw
attr_accessor :iv

def initialize(key = nil, iv = "\xA6\xA6\xA6\xA6\xA6\xA6\xA6\xA6")
self.iv = iv.force_encoding('ASCII-8BIT')
self.key = key.force_encoding('ASCII-8BIT')
self.iv = iv.b
self.key = key.b
end

def encrypt(cek)
a = iv
r = cek.force_encoding('ASCII-8BIT').scan(/.{8}/m)
r = cek.b.scan(/.{8}/m)

6.times do |j|
a, r = kw_encrypt_round(j, a, r)
Expand All @@ -36,7 +38,7 @@ def kw_encrypt_round(j, a, r)
end

def decrypt(encrypted_cek)
c = encrypted_cek.force_encoding('ASCII-8BIT').scan(/.{8}/m)
c = encrypted_cek.b.scan(/.{8}/m)
a, *r = c

5.downto(0) do |j|
Expand Down

0 comments on commit 5a2962c

Please sign in to comment.