Keep identical state in Sodium::SecureBuffer#dup
This commit is contained in:
parent
3124048a43
commit
38bd985103
@ -23,6 +23,7 @@ Notes:
|
|||||||
* Sodium::Cipher::SecretStream
|
* Sodium::Cipher::SecretStream
|
||||||
* Sodium::Digest::Blake2b
|
* Sodium::Digest::Blake2b
|
||||||
* Sodium::Kdf
|
* Sodium::Kdf
|
||||||
|
* Sodium::SecureBuffer
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
* Use one instance per thread or wrap in a `Mutex`.
|
* Use one instance per thread or wrap in a `Mutex`.
|
||||||
|
@ -41,9 +41,10 @@ describe Sodium::SecureBuffer do
|
|||||||
buf.readwrite
|
buf.readwrite
|
||||||
|
|
||||||
buf2 = buf.dup
|
buf2 = buf.dup
|
||||||
buf2.readonly
|
buf2.@state.should eq Sodium::SecureBuffer::State::Readwrite
|
||||||
|
|
||||||
buf[0] = 0_u8
|
buf[0] = 0_u8
|
||||||
|
buf2[0] = 0_u8
|
||||||
end
|
end
|
||||||
|
|
||||||
it "transitions correctly" do
|
it "transitions correctly" do
|
||||||
|
@ -13,6 +13,7 @@ module Sodium
|
|||||||
end
|
end
|
||||||
|
|
||||||
enum State
|
enum State
|
||||||
|
Cloning
|
||||||
Wiped
|
Wiped
|
||||||
Noaccess
|
Noaccess
|
||||||
Readonly
|
Readonly
|
||||||
@ -49,11 +50,14 @@ module Sodium
|
|||||||
# For .dup
|
# For .dup
|
||||||
def initialize(sbuf : self)
|
def initialize(sbuf : self)
|
||||||
initialize sbuf.bytesize
|
initialize sbuf.bytesize
|
||||||
|
|
||||||
# Maybe not thread safe
|
# Maybe not thread safe
|
||||||
sbuf.readonly do
|
sbuf.readonly do
|
||||||
sbuf.to_slice.copy_to self.to_slice
|
sbuf.to_slice.copy_to self.to_slice
|
||||||
end
|
end
|
||||||
readonly
|
|
||||||
|
@state = State::Cloning
|
||||||
|
set_state sbuf.@state
|
||||||
end
|
end
|
||||||
|
|
||||||
def wipe
|
def wipe
|
||||||
|
Loading…
Reference in New Issue
Block a user