Exemple #1
0
        public static PaymentRequest Load(Stream source)
        {
            var result = new PaymentRequest();
            var req    = Serializer.Deserialize <Proto.PaymentRequest>(source);

            result.PKIType = ToPKIType(req.pki_type);
            if (req.pki_data != null && req.pki_data.Length != 0)
            {
                var  certs = Serializer.Deserialize <Proto.X509Certificates>(new MemoryStream(req.pki_data));
                bool first = true;
                foreach (var cert in certs.certificate)
                {
                    if (first)
                    {
                        first = false;
                        result.MerchantCertificate = new X509Certificate2(cert);
                    }
                    else
                    {
                        result.AdditionalCertificates.Add(new X509Certificate2(cert));
                    }
                }
            }
            result._PaymentDetails = PaymentDetails.Load(req.serialized_payment_details);
            result.Signature       = req.signature;
            result.OriginalData    = req;
            return(result);
        }
Exemple #2
0
        public static PaymentRequest Load(Stream source, out byte[] signed)
        {
            RecorderStream record          = new RecorderStream(source);
            PaymentRequest req             = new PaymentRequest();
            var            reader          = new ProtobufReaderWriter(record);
            bool           signatureLoaded = false;
            int            key;
            bool           firstCert = true;

            while (reader.TryReadKey(out key))
            {
                switch (key)
                {
                case 1:
                    req.DetailsVersion = (uint)reader.ReadULong();
                    break;

                case 2:
                    req.PKIType = ToPKIType(reader.ReadString());
                    break;

                case 3:
                    var bytes = reader.ReadBytes();
                    ProtobufReaderWriter certs = new ProtobufReaderWriter(new MemoryStream(bytes));
                    int k;
                    while (certs.TryReadKey(out k))
                    {
                        if (firstCert)
                        {
                            req.MerchantCertificate = certs.ReadBytes();
                            firstCert = false;
                        }
                        else
                        {
                            req.AdditionalCertificates.Add(certs.ReadBytes());
                        }
                    }
                    break;

                case 4:
                    req._PaymentDetails = PaymentDetails.Load(reader.ReadBytes());
                    break;

                case 5:
                    record.Activated = false;
                    req.Signature    = reader.ReadBytes();
                    signatureLoaded  = req.Signature.Length != 0;
                    record.Activated = true;
                    record.RecordBytes(new byte[0]);
                    break;

                default:
                    break;
                }
            }
            signed = record.ToBytes();
            return(req);
        }