Fix Secret.bytesize delegates

This commit is contained in:
Didactic Drunk 2021-06-14 16:54:29 -07:00
parent 4a32468d7d
commit b738cd1e0a
3 changed files with 22 additions and 11 deletions

View File

@ -20,6 +20,11 @@ describe Crypto::Secret::Not do
end end
end end
it "bytesize" do
secret = Crypto::Secret::Not.new 5
secret.bytesize.should eq 5
end
it "doesn't leak key material" do it "doesn't leak key material" do
secret = Crypto::Secret::Not.new 5 secret = Crypto::Secret::Not.new 5
secret.to_s.should match /\(\*\*\*SECRET\*\*\*\)$/ secret.to_s.should match /\(\*\*\*SECRET\*\*\*\)$/

View File

@ -5,8 +5,10 @@ require "./stateless"
# Not locked in memory # Not locked in memory
# Not access protected # Not access protected
# No guard pages # No guard pages
struct Crypto::Secret::Not # Doesn't wipe
include Crypto::Secret::Stateless module Crypto::Secret
struct Not
include Stateless
def self.new(size) def self.new(size)
new Bytes.new(size) new Bytes.new(size)
@ -16,5 +18,9 @@ struct Crypto::Secret::Not
end end
delegate_to_slice @bytes delegate_to_slice @bytes
delegate_to_bytesize @bytes delegate_to_bytesize @bytes.bytesize
def wipe
end
end
end end

View File

@ -90,7 +90,7 @@ module Crypto::Secret
macro delegate_to_bytesize(to object) macro delegate_to_bytesize(to object)
def bytesize : Int32 def bytesize : Int32
{{object.id}}.bytesize {{object.id}}
end end
end end