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
it "bytesize" do
secret = Crypto::Secret::Not.new 5
secret.bytesize.should eq 5
end
it "doesn't leak key material" do
secret = Crypto::Secret::Not.new 5
secret.to_s.should match /\(\*\*\*SECRET\*\*\*\)$/

View File

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

View File

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