···44 it "should make a key from a password and salt" do
55 b64 = "2K4YP5Om9r5NpA7FCS4vQX5t+IC4hKYdTJN/C20cz9c="
6677- k = Bitwarden.makeKey("this is a password", "nobody@example.com", 5000)
77+ k = Bitwarden.makeKey("this is a password", "nobody@example.com",
88+ Bitwarden::KDF::PBKDF2, 5000)
89 Base64.strict_encode64(k).encode("utf-8").must_equal b64
9101011 # make sure key and salt affect it
1111- k = Bitwarden.makeKey("this is a password", "nobody2@example.com", 5000)
1212+ k = Bitwarden.makeKey("this is a password", "nobody2@example.com",
1313+ Bitwarden::KDF::PBKDF2, 5000)
1214 Base64.strict_encode64(k).encode("utf-8").wont_equal b64
13151414- k = Bitwarden.makeKey("this is A password", "nobody@example.com", 5000)
1616+ k = Bitwarden.makeKey("this is A password", "nobody@example.com",
1717+ Bitwarden::KDF::PBKDF2, 5000)
1518 Base64.strict_encode64(k).encode("utf-8").wont_equal b64
1619 end
17201821 it "should make a cipher string from a key" do
1922 cs = Bitwarden.makeEncKey(
2020- Bitwarden.makeKey("this is a password", "nobody@example.com", 5000)
2323+ Bitwarden.makeKey("this is a password", "nobody@example.com",
2424+ Bitwarden::KDF::PBKDF2, 5000)
2125 )
22262327 cs.must_match(/^0\.[^|]+|[^|]+$/)
···25292630 it "should hash a password" do
2731 #def hashedPassword(password, salt)
2828- Bitwarden.hashPassword("secret password", "user@example.com", 5000).
2929- must_equal "VRlYxg0x41v40mvDNHljqpHcqlIFwQSzegeq+POW1ww="
3232+ Bitwarden.hashPassword("secret password", "user@example.com",
3333+ Bitwarden::KDF::PBKDF2, 5000).must_equal "VRlYxg0x41v40mvDNHljqpHcqlIFwQSzegeq+POW1ww="
3034 end
31353236 it "should parse a cipher string" do
···4650 end
47514852 it "should encrypt and decrypt properly" do
4949- ik = Bitwarden.makeKey("password", "user@example.com", 5000)
5353+ ik = Bitwarden.makeKey("password", "user@example.com",
5454+ Bitwarden::KDF::PBKDF2, 5000)
5055 ek = Bitwarden.makeEncKey(ik)
5156 k = Bitwarden.decrypt(ek, ik, nil)
5257 j = Bitwarden.encrypt("hi there", k[0, 32], k[32, 32])
53585459 cs = Bitwarden::CipherString.parse(j)
55605656- ik = Bitwarden.makeKey("password", "user@example.com", 5000)
6161+ ik = Bitwarden.makeKey("password", "user@example.com",
6262+ Bitwarden::KDF::PBKDF2, 5000)
5763 Bitwarden.decrypt(cs.to_s, k[0, 32], k[32, 32]).must_equal "hi there"
5864 end
5965