Keep identical state in Sodium::SecureBuffer#dup

master
Didactic Drunk 2021-05-16 22:42:49 -07:00
parent 3124048a43
commit 38bd985103
3 changed files with 8 additions and 2 deletions

View File

@ -23,6 +23,7 @@ Notes:
* Sodium::Cipher::SecretStream
* Sodium::Digest::Blake2b
* Sodium::Kdf
* Sodium::SecureBuffer
Notes:
* Use one instance per thread or wrap in a `Mutex`.

View File

@ -41,9 +41,10 @@ describe Sodium::SecureBuffer do
buf.readwrite
buf2 = buf.dup
buf2.readonly
buf2.@state.should eq Sodium::SecureBuffer::State::Readwrite
buf[0] = 0_u8
buf2[0] = 0_u8
end
it "transitions correctly" do

View File

@ -13,6 +13,7 @@ module Sodium
end
enum State
Cloning
Wiped
Noaccess
Readonly
@ -49,11 +50,14 @@ module Sodium
# For .dup
def initialize(sbuf : self)
initialize sbuf.bytesize
# Maybe not thread safe
sbuf.readonly do
sbuf.to_slice.copy_to self.to_slice
end
readonly
@state = State::Cloning
set_state sbuf.@state
end
def wipe