Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/services/irs_attempts_api/envelope_encryptor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'base16'

module IrsAttemptsApi
class EnvelopeEncryptor
Result = Struct.new(:filename, :iv, :encrypted_key, :encrypted_data, keyword_init: true)
Expand Down
1 change: 0 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
require_relative '../lib/fingerprinter'
require_relative '../lib/identity_job_log_subscriber'
require_relative '../lib/email_delivery_observer'
require_relative '../lib/base_16' # Should I need to do this?

Bundler.require(*Rails.groups)

Expand Down
10 changes: 10 additions & 0 deletions lib/base16.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See https://www.rfc-editor.org/rfc/rfc4648#section-8
class Base16
def self.encode16(str)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will matter more in context as well, but another option is for us to shell out to xxd. I think once we start experimenting with big encrypting, we might just write the raw data to a file and shell out to xxd | gzip or something and I think that will be faster than doing things in ruby

str.unpack('H*').first.tap(&:upcase!)
end

def self.decode16(str)
[str].pack('H*')
end
end
16 changes: 0 additions & 16 deletions lib/base_16.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/tasks/attempts.rake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'base16'

namespace :attempts do
desc 'Retrieve events via the API'
task fetch_events: :environment do
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/base16_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rails_helper'
require 'base16'

RSpec.describe Base16 do

Expand Down Expand Up @@ -34,12 +35,12 @@
end
end

context 'with a less reasonable input', skip: true do
context 'with a less reasonable input' do
context 'given a zany-face emoji' do
let(:input) { "🤪" }
it 'should return the same thing but does not' do
it 'returns the same bytes' do
encoded = described_class.encode16(input)
decoded = described_class.decode16(encoded)
decoded = described_class.decode16(encoded).force_encoding('UTF-8')
expect(decoded).to eq input
end
end
Expand Down