From 53b44e6ecde47c63a0426fe2366be5f0f962342e Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Wed, 16 Jun 2021 19:47:38 -0700 Subject: [PATCH] Check .dup state when Stateful --- src/crypto-secret/lib.cr | 7 +++++++ src/crypto-secret/stateful.cr | 4 +++- src/crypto-secret/test.cr | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/crypto-secret/lib.cr b/src/crypto-secret/lib.cr index 106236a..2d1de71 100644 --- a/src/crypto-secret/lib.cr +++ b/src/crypto-secret/lib.cr @@ -1,4 +1,11 @@ module Crypto + module Secret + module Stateless + end + + module Stateful + end + end end require "crypto/subtle" diff --git a/src/crypto-secret/stateful.cr b/src/crypto-secret/stateful.cr index c8aeeb4..ecdae6a 100644 --- a/src/crypto-secret/stateful.cr +++ b/src/crypto-secret/stateful.cr @@ -66,7 +66,9 @@ module Crypto::Secret end # WARNING: Not thread safe - private def set_state(new_state : State) + # Kept public for .dup + # :nodoc: + def set_state(new_state : State) return if @state == new_state case new_state diff --git a/src/crypto-secret/test.cr b/src/crypto-secret/test.cr index 6582319..c2addbd 100644 --- a/src/crypto-secret/test.cr +++ b/src/crypto-secret/test.cr @@ -56,9 +56,11 @@ macro test_secret_class(to sclass) secret1 = sclass.copy_from key secret2 = secret1.dup (secret1 == secret2).should be_true - end - pending "check dup state" { } + if secret1.is_a?(Crypto::Secret::Stateful) && secret2.is_a?(Crypto::Secret::Stateful) + secret1.@state.should eq secret2.@state + end + end it "bytesize" do secret = sclass.new 5