spec/string_security_spec.rb in dionysus-0.2.0 vs spec/string_security_spec.rb in dionysus-0.2.1
- old
+ new
@@ -11,101 +11,154 @@
String.salt(1).length.should == 1
end
it "should calculate sha512 in base64" do
digest = "KHErTuI/5urCF3vi6yTDxvAHBydW1CN3zVfBWDP/ItbmgeVi5IFq47ew0hPHzyK3AuMDh+Z9MBBlf3/mACgVMQ=="
+ "abcde\240z405".digest(:sha512).should == digest
"abcde\240z405".sha512.should == digest
"abcde\240z405".sha512(:encoding => :base64).should == digest
end
+ it "should calculate sha384 in base64" do
+ digest = "PcQPzxc6tAaom+DG31XCi/A/7ZB6N0PgkBK9e1NMOadc7VxYSWoGq03f2+DiflT5"
+ "abcde\240z405".digest(:sha384).should == digest
+ "abcde\240z405".sha384.should == digest
+ "abcde\240z405".sha384(:encoding => :base64).should == digest
+ end
+
it "should calculate sha256/sha2 in base64" do
digest = "vGeWpAMcqj2XuE8P4FirA2oUt1S78c6puQk03EOdnQY="
+ "abcde\240z405".digest(:sha256).should == digest
"abcde\240z405".sha256.should == digest
"abcde\240z405".sha256(:encoding => :base64).should == digest
+ "abcde\240z405".digest(:sha2).should == digest
"abcde\240z405".sha2.should == digest
"abcde\240z405".sha2(:encoding => :base64).should == digest
end
it "should calculate sha1 in base64" do
digest = "wxeCFXPVXePFcpwuFDjonyn1G/w="
+ "abcde\240z405".digest(:sha1).should == digest
"abcde\240z405".sha1.should == digest
"abcde\240z405".sha1(:encoding => :base64).should == digest
end
it "should calculate md5 in base64" do
digest = "ThT0y7KbAinjLpuChqsRuQ=="
+ "abcde\240z405".digest(:md5).should == digest
"abcde\240z405".md5.should == digest
"abcde\240z405".md5(:encoding => :base64).should == digest
end
it "should calculate sha512 with a salt" do
salt = 'abcdefg'
digest = "oxoD5Mwq6ck4B1P2tfsrCQnNHzBYQRKOFGTj1T0EFPWeNuy1/YPtsKGiz2os9ljt0/OwXEt/l8LsK/ktbwEHbg=="
+ "abcde\240z405".digest(:sha512, :salt => salt).should == digest
"abcde\240z405".sha512(:salt => salt).should == digest
end
+ it "should calculate sha384 with a salt" do
+ salt = 'abcdefg'
+ digest = "XVHvPSZDdUNC8zY0oriwlXfwhMPeJusx59kWkGq3bEqrz1tlbmMJ+UGUOqYKbdYK"
+ "abcde\240z405".digest(:sha384, :salt => salt).should == digest
+ "abcde\240z405".sha384(:salt => salt).should == digest
+ end
+
it "should calculate sha256/sha2 with a salt" do
salt = 'abcdefg'
digest = "fWzU2g2GFAS5EAgTS09djo2eDDQdNp1xSTdrRO7m9v4="
+ "abcde\240z405".digest(:sha256, :salt => salt).should == digest
"abcde\240z405".sha256(:salt => salt).should == digest
+ "abcde\240z405".digest(:sha2, :salt => salt).should == digest
"abcde\240z405".sha2(:salt => salt).should == digest
end
it "should calculate sha1 with a salt" do
salt = 'abcdefg'
digest = "JFdwlGl341qtbqX6mPQbjs8d1/U="
+ "abcde\240z405".digest(:sha1, :salt => salt).should == digest
"abcde\240z405".sha1(:salt => salt).should == digest
end
it "should calculate md5 with a salt" do
salt = 'abcdefg'
digest = "m59029ys/bc2HpeuZqcQ3w=="
+ "abcde\240z405".digest(:md5, :salt => salt).should == digest
"abcde\240z405".md5(:salt => salt).should == digest
end
it "should calculate sha512 in hex/hexidecimal" do
digest = "28712b4ee23fe6eac2177be2eb24c3c6f007072756d42377cd57c15833ff22d6e681e562e4816ae3b7b0d213c7cf22b702e30387e67d3010657f7fe600281531"
+ "abcde\240z405".digest(:sha512, :encoding => :hex).should == digest
+ "abcde\240z405".digest(:sha512, :encoding => :hexidecimal).should == digest
"abcde\240z405".sha512(:encoding => :hex).should == digest
"abcde\240z405".sha512(:encoding => :hexidecimal).should == digest
end
+ it "should calculate sha384 in hex/hexidecimal" do
+ digest = "3dc40fcf173ab406a89be0c6df55c28bf03fed907a3743e09012bd7b534c39a75ced5c58496a06ab4ddfdbe0e27e54f9"
+ "abcde\240z405".digest(:sha384, :encoding => :hex).should == digest
+ "abcde\240z405".digest(:sha384, :encoding => :hexidecimal).should == digest
+ "abcde\240z405".sha384(:encoding => :hex).should == digest
+ "abcde\240z405".sha384(:encoding => :hexidecimal).should == digest
+ end
+
it "should calculate sha256/sha2 in hex/hexidecimal" do
digest = "bc6796a4031caa3d97b84f0fe058ab036a14b754bbf1cea9b90934dc439d9d06"
+ "abcde\240z405".digest(:sha256, :encoding => :hex).should == digest
+ "abcde\240z405".digest(:sha256, :encoding => :hexidecimal).should == digest
+ "abcde\240z405".digest(:sha2, :encoding => :hex).should == digest
+ "abcde\240z405".digest(:sha2, :encoding => :hexidecimal).should == digest
"abcde\240z405".sha256(:encoding => :hex).should == digest
"abcde\240z405".sha2(:encoding => :hex).should == digest
"abcde\240z405".sha256(:encoding => :hexidecimal).should == digest
"abcde\240z405".sha2(:encoding => :hexidecimal).should == digest
end
it "should calculate sha1 in hex/hexidecimal" do
digest = "c317821573d55de3c5729c2e1438e89f29f51bfc"
+ "abcde\240z405".digest(:sha1, :encoding => :hex).should == digest
+ "abcde\240z405".digest(:sha1, :encoding => :hexidecimal).should == digest
"abcde\240z405".sha1(:encoding => :hex).should == digest
"abcde\240z405".sha1(:encoding => :hexidecimal).should == digest
end
it "should calculate md5 in hex/hexidecimal" do
digest = "4e14f4cbb29b0229e32e9b8286ab11b9"
+ "abcde\240z405".digest(:md5, :encoding => :hex).should == digest
+ "abcde\240z405".digest(:md5, :encoding => :hexidecimal).should == digest
"abcde\240z405".md5(:encoding => :hex).should == digest
"abcde\240z405".md5(:encoding => :hexidecimal).should == digest
end
it "should calculate sha512 in binary" do
digest = "(q+N\342?\346\352\302\027{\342\353$\303\306\360\a\a'V\324#w\315W\301X3\377\"\326\346\201\345b\344\201j\343\267\260\322\023\307\317\"\267\002\343\003\207\346}0\020e\177\177\346\000(\0251"
+ "abcde\240z405".digest(:sha512, :encoding => :binary).should == digest
"abcde\240z405".sha512(:encoding => :binary).should == digest
end
+ it "should calculate sha384 in binary" do
+ digest = "=\304\017\317\027:\264\006\250\233\340\306\337U\302\213\360?\355\220z7C\340\220\022\275{SL9\247\\\355\\XIj\006\253M\337\333\340\342~T\371"
+ "abcde\240z405".digest(:sha384, :encoding => :binary).should == digest
+ "abcde\240z405".sha384(:encoding => :binary).should == digest
+ end
+
it "should calculate sha256/sha2 in binary" do
digest = "\274g\226\244\003\034\252=\227\270O\017\340X\253\003j\024\267T\273\361\316\251\271\t4\334C\235\235\006"
+ "abcde\240z405".digest(:sha256, :encoding => :binary).should == digest
+ "abcde\240z405".digest(:sha2, :encoding => :binary).should == digest
"abcde\240z405".sha256(:encoding => :binary).should == digest
"abcde\240z405".sha2(:encoding => :binary).should == digest
end
it "should calculate sha1 in binary" do
digest = "\303\027\202\025s\325]\343\305r\234.\0248\350\237)\365\e\374"
+ "abcde\240z405".digest(:sha1, :encoding => :binary).should == digest
"abcde\240z405".sha1(:encoding => :binary).should == digest
end
it "should calculate md5 in binary" do
digest = "N\024\364\313\262\233\002)\343.\233\202\206\253\021\271"
+ "abcde\240z405".digest(:md5, :encoding => :binary).should == digest
"abcde\240z405".md5(:encoding => :binary).should == digest
end
end