Keep identical state in Sodium::SecureBuffer#dup
parent
3124048a43
commit
38bd985103
|
@ -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`.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue