/// <summary> /// Initializes a new instance of the <see cref="BfdRequest"/> class with a specified best finger detection data received from device. /// </summary> /// <param name="bfdContext">The finger data received from device.</param> /// <exception cref="System.ArgumentNullException"><paramref name="bfdContext"/> is null.</exception> public BfdRequest(BfdContext bfdContext) { ValidateNull(bfdContext, nameof(bfdContext)); AadhaarNumber = bfdContext.AadhaarNumber; Data = bfdContext.Data; DeviceInfo = bfdContext.DeviceInfo; Hmac = bfdContext.Hmac; KeyInfo = bfdContext.KeyInfo; Terminal = bfdContext.Terminal; }
public void EncryptTest() { var bfdContext = new BfdContext { DeviceInfo = Data.Metadata, Terminal = Data.PublicTerminal }; // Test 1: Validate null argument. Assert.Throws <ArgumentNullException>("key", () => bfdContext.Encrypt(Data.BestFingerInfo, null)); Assert.Throws <ArgumentNullException>("data", () => bfdContext.Encrypt(null, Data.SessionKey)); // Test 2: All fields are set after call. bfdContext.Encrypt(Data.BestFingerInfo, Data.SessionKey); Assert.NotNull(bfdContext.AadhaarNumber); Assert.NotNull(bfdContext.Data); Assert.NotNull(bfdContext.DeviceInfo); Assert.NotNull(bfdContext.Hmac); Assert.NotNull(bfdContext.KeyInfo); Assert.Equal(Data.PersonalInfo.Timestamp, bfdContext.Timestamp); // Test 3: DeviceInfo device value are set to NA. Assert.Equal(Metadata.DeviceNotApplicable, bfdContext.DeviceInfo.IrisDeviceCode); }
public static async Task BestFingerDetectionAsync() { #region Device Level // Set Best Finger Info var bestFingerInfo = new BestFingerInfo { AadhaarNumber = "999999990019" }; bestFingerInfo.Fingers.Add(new TestFinger { Quality = Nfiq.Excellent, NumberOfAttempts = 3, Position = BiometricPosition.LeftIndex, Data = BiometricData }); bestFingerInfo.Fingers.Add(new TestFinger { Quality = Nfiq.Excellent, NumberOfAttempts = 4, Position = BiometricPosition.LeftMiddle, Data = BiometricData }); bestFingerInfo.Fingers.Add(new TestFinger { Quality = Nfiq.Excellent, NumberOfAttempts = 5, Position = BiometricPosition.LeftRing, Data = BiometricData }); // Set Device Info var bfdContext = new BfdContext { DeviceInfo = Configuration.Current.DeviceInfo.Create() }; // Encrypt Data var sessionKey = new SessionKey(Configuration.Current.UidaiEncryption, false); await bfdContext.EncryptAsync(bestFingerInfo, sessionKey); #endregion #region Device To Agency // TODO: Wrap DeviceContext{T} into AUA specific protocol and send it to AUA. // On Device Side: // var deviceXml = deviceContext.ToXml(); // var wrapped = WrapIntoAuaProtocol(deviceXml); // On Agency Side: // var auaXml = UnwrapFromAuaProtocol(wrapped); // var auaContext = new BfdContext(); // auaContext.FromXml(auaXml); #endregion #region Agency Level // Perform Best Finger Detection var bfdClient = new BfdClient { AgencyInfo = Configuration.Current.AgencyInfo, Request = new BfdRequest(bfdContext) { Signer = XmlSignature }, Response = new BfdResponse { Verifier = XmlSignature } }; await bfdClient.GetResponseAsync(); Console.WriteLine(string.IsNullOrEmpty(bfdClient.Response.ErrorCode) ? $"Best Finger Is: {bfdClient.Response.Ranks.First().Value}" : $"Error Code: {bfdClient.Response.ErrorCode}"); #endregion #region Agency To Device // TODO: Wrap BfdResponse into AUA specific protocol and send it to device. #endregion }