public void Equals_NotEqual() { var value1 = new FidoPublicKey(Encoding.Default.GetBytes("publickey")); var value2 = new FidoPublicKey(Encoding.Default.GetBytes("Publickey")); Assert.IsFalse(value1.Equals(value2)); }
private static FidoDeviceRegistration CreateTestDeviceRegistration() { var cert = FidoAttestationCertificate.FromWebSafeBase64(TestVectors.AttestationCertificate); var keyHandle = FidoKeyHandle.FromWebSafeBase64(TestVectors.KeyHandle); var publicKey = FidoPublicKey.FromWebSafeBase64(TestVectors.PublicKeyBase64); return(new FidoDeviceRegistration(keyHandle, publicKey, cert, 0)); }
private FidoRegistrationData(FidoPublicKey userPublicKey, FidoKeyHandle keyHandle, FidoAttestationCertificate attestationCertificate, FidoSignature signature) { UserPublicKey = userPublicKey; KeyHandle = keyHandle; AttestationCertificate = attestationCertificate; Signature = signature; }
private static FidoDeviceRegistration CreateTestDeviceRegistration() { var keyHandle = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle")); var publicKey = new FidoPublicKey(Encoding.Default.GetBytes("publickey")); var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate")); var deviceRegistration = new FidoDeviceRegistration(keyHandle, publicKey, certificate, 12345); return(deviceRegistration); }
public void SerializeObject() { var randomBytes = new byte[256]; RandomNumberGenerator.Create().GetBytes(randomBytes); var value = new FidoPublicKey(randomBytes); var serialized = JsonConvert.SerializeObject(value); var bytes = WebSafeBase64Converter.FromBase64String(serialized.Trim('"')); Assert.IsTrue(randomBytes.SequenceEqual(bytes)); }
public void DeserializeObject() { var publicKey = new byte[256]; RandomNumberGenerator.Create().GetBytes(publicKey); var value = new FidoPublicKey(publicKey); var serialized = JsonConvert.SerializeObject(value); var deserialized = JsonConvert.DeserializeObject<FidoPublicKey>(serialized); Assert.AreEqual(value, deserialized); }
public void FromJson() { var deviceRegistration = FidoDeviceRegistration.FromJson("{\"Certificate\":\"Y2VydGlmaWNhdGU\",\"Counter\":12345,\"KeyHandle\":\"a2V5aGFuZGxl\",\"PublicKey\":\"cHVibGlja2V5\"}"); var keyHandle = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle")); var publicKey = new FidoPublicKey(Encoding.Default.GetBytes("publickey")); var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate")); Assert.AreEqual(12345, deviceRegistration.Counter); Assert.IsTrue(certificate.Equals(deviceRegistration.Certificate)); Assert.IsTrue(publicKey.Equals(deviceRegistration.PublicKey)); Assert.IsTrue(keyHandle.Equals(deviceRegistration.KeyHandle)); }
public void DeserializeObject() { var publicKey = new byte[256]; RandomNumberGenerator.Create().GetBytes(publicKey); var value = new FidoPublicKey(publicKey); var serialized = JsonConvert.SerializeObject(value); var deserialized = JsonConvert.DeserializeObject <FidoPublicKey>(serialized); Assert.AreEqual(value, deserialized); }
public void ToJson() { var keyHandle = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle")); var publicKey = new FidoPublicKey(Encoding.Default.GetBytes("publickey")); var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate")); var deviceRegistration = new FidoDeviceRegistration(keyHandle, publicKey, certificate, 12345); var serialized = deviceRegistration.ToJson(); var jsonObject = JObject.Parse(serialized); var properties = jsonObject.Properties().ToLookup(x => x.Name.ToLowerInvariant(), x => x.Value.ToString()); Assert.AreEqual("Y2VydGlmaWNhdGU", properties["certificate"].Single()); Assert.AreEqual("12345", properties["counter"].Single()); Assert.AreEqual("a2V5aGFuZGxl", properties["keyhandle"].Single()); Assert.AreEqual("cHVibGlja2V5", properties["publickey"].Single()); }
public void Validate_Good_NoException() { var value = new FidoPublicKey(WebSafeBase64Converter.FromBase64String(TestVectors.PublicKeyBase64)); value.Validate(); }
public void Validate_InvalidBytes_Throws() { var value = new FidoPublicKey(new byte[65]); Assert.Throws<ArgumentException>(() => value.Validate()); }
public void Validate_BytesEmpty_Throws() { var value = new FidoPublicKey(new byte[0]); Assert.Throws<InvalidOperationException>(() => value.Validate()); }
public void Constructor() { var value = new FidoPublicKey(Encoding.Default.GetBytes("publickey")); Assert.AreEqual("publickey", Encoding.Default.GetString(value.ToByteArray())); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return(FidoPublicKey.FromWebSafeBase64(reader.Value.ToString())); }
public void Validate_InvalidBytes_Throws() { var value = new FidoPublicKey(new byte[65]); Assert.Throws <ArgumentException>(() => value.Validate()); }
public void Validate_BytesEmpty_Throws() { var value = new FidoPublicKey(new byte[0]); Assert.Throws <InvalidOperationException>(() => value.Validate()); }
public void Equals_Null() { Assert.IsFalse(FidoPublicKey.FromWebSafeBase64("").Equals(null)); }
private static FidoDeviceRegistration CreateTestDeviceRegistration() { var keyHandle = new FidoKeyHandle(Encoding.Default.GetBytes("keyhandle")); var publicKey = new FidoPublicKey(Encoding.Default.GetBytes("publickey")); var certificate = new FidoAttestationCertificate(Encoding.Default.GetBytes("certificate")); var deviceRegistration = new FidoDeviceRegistration(keyHandle, publicKey, certificate, 12345); return deviceRegistration; }