private IResult RequestReset(ISmartCardState smartCardState, ISmartCardData smartCardData)
        {
            if (!IsAuthenticated(smartCardState, smartCardData))
            {
                return(SmartCardResult
                       .CreateError(Result.StripeResetRejected));
            }

            smartCardState.Stripe = Array.Empty <char>();
            return(SmartCardResult
                   .Create(Pin.Acknowledge, Code.Accepted, Result.StripeResetCompleted));
        }
        public virtual IResult Handle(Code code, ISmartCardState smartCardState, ISmartCardData cardData)
        {
            var action = PinServiceHandleSwitch.Case(code);

            if (action == null)
            {
                return(SmartCardResult
                       .CreateError(Result.UndeterminedResult, Code.Error));
            }

            return(action.Invoke(smartCardState, cardData));
        }
        private IResult Connect(ISmartCardState smartCardState, ISmartCardData smartCardData)
        {
            if (!IsAuthenticated(smartCardState, smartCardData))
            {
                return(SmartCardResult.CreateError(Result.Unauthorised, Code.Rejected));
            }

            if (smartCardState.IsConnected)
            {
                return(SmartCardResult.CreateError(Result.AlreadyConnected, Code.Rejected));
            }

            smartCardState.IsConnected = true;
            return(SmartCardResult.Create(Pin.Acknowledge, Code.Accepted, Result.Connected));
        }
        private IResult BeginTransmit(ISmartCardState smartCardState, ISmartCardData smartCardData)
        {
            if (!IsAuthenticated(smartCardState, smartCardData))
            {
                return(SmartCardResult.CreateError(Result.Unauthorised, Code.Rejected));
            }

            if (smartCardState.IsTransmitting)
            {
                return(SmartCardResult.CreateError(Result.RecieveFailure, Code.Denied));
            }

            smartCardState.IsTransmitting = true;

            return(SmartCardResult.Create(Pin.Acknowledge, Code.Accepted, Result.TransmissionEnded));
        }
        private IResult BinaryTransmit(ISmartCardState smartCardState, ISmartCardData smartCardData)
        {
            if (!IsAuthenticated(smartCardState, smartCardData))
            {
                return(SmartCardResult.CreateError(Result.Unauthorised, Code.Rejected));
            }

            if (!smartCardState.IsTransmitting)
            {
                return(SmartCardResult.CreateError(Result.RecieveFailure, Code.Denied));
            }

            smartCardState.Transmission = smartCardState.Transmission.Append(smartCardData.Data);

            return(SmartCardResult.Create(Pin.Acknowledge, Code.Accepted, Result.ContinueTransmission));
        }
        private IResult Authenticate(ISmartCardState smartCardState, ISmartCardData smartCardData)
        {
            if (IsAuthenticated(smartCardState, smartCardData) ||
                (smartCardState.Stripe != null && smartCardState.Stripe.Any()))
            {
                return(SmartCardResult.CreateError(Result.AlreadyAuthenticated));
            }

            if (smartCardState.IsConnected)
            {
                return(SmartCardResult.CreateError(Result.AlreadyConnected, Code.Rejected));
            }

            smartCardState.Stripe = smartCardData.Stripe;
            return(SmartCardResult
                   .Create(Pin.Acknowledge, Code.Accepted, Result.AuthenticationSucceeded));
        }
Exemple #7
0
        private IResult Handle(ISmartCardData cardData)
        {
            var pin  = SmartCardData.GetPin(cardData.Pin);
            var code = SmartCardData.GetCode(cardData.Code);

            var pinService = _pinServiceFactory
                             .GetPinService(pin);

            if (pinService == null)
            {
                return(SmartCardResult
                       .CreateError(Result.UndeterminedResult));
            }

            return(pinService
                   .Handle(code, _smartCardState, cardData));
        }
Exemple #8
0
 public ISmartCardData Input(ISmartCardData cardData)
 {
     return(SmartCardData.Create(Handle(cardData)));
 }
 private IResult DataTransmit(ISmartCardState smartCardState, ISmartCardData smartCardData)
 {
     return(BinaryTransmit(smartCardState, smartCardData));
 }
 protected static bool IsAuthenticated(ISmartCardState smartCardState, ISmartCardData smartCard)
 {
     return(smartCardState.Stripe != null &&
            smartCardState.Stripe.SequenceEqual(smartCard.Stripe));
 }