Exemple #1
0
        public CertificateProfile(string name = null, CertificateProfileType type = CertificateProfileType.Unknown, MailAddress emailAddress = null, Uri website = null, string phoneNumber = null, string streetAddress = null, string city = null, string state = null, string country = null, string postalCode = null, CertificateProfileFlags verificationFlags = CertificateProfileFlags.None)
        {
            _version  = 1;
            _verified = verificationFlags;

            if (name != null)
            {
                _name   = name;
                _flags |= CertificateProfileFlags.Name;
            }

            if (type != CertificateProfileType.Unknown)
            {
                _type   = type;
                _flags |= CertificateProfileFlags.Type;
            }

            if (emailAddress != null)
            {
                _emailAddress = emailAddress;
                _flags       |= CertificateProfileFlags.EmailAddress;
            }

            if (website != null)
            {
                _website = website;
                _flags  |= CertificateProfileFlags.Website;
            }

            if (phoneNumber != null)
            {
                _phoneNumber = phoneNumber;
                _flags      |= CertificateProfileFlags.PhoneNumber;
            }

            if (streetAddress != null)
            {
                _streetAddress = streetAddress;
                _flags        |= CertificateProfileFlags.StreetAddress;
            }

            if (city != null)
            {
                _city   = city;
                _flags |= CertificateProfileFlags.City;
            }

            if (state != null)
            {
                _state  = state;
                _flags |= CertificateProfileFlags.State;
            }

            if (country != null)
            {
                _country = country;
                _flags  |= CertificateProfileFlags.Country;
            }

            if (postalCode != null)
            {
                _postalCode = postalCode;
                _flags     |= CertificateProfileFlags.PostalCode;
            }

            _verified = _verified & _flags;
        }
Exemple #2
0
        public CertificateProfile(Stream s)
        {
            BinaryReader bR = new BinaryReader(s);

            if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "CP")
            {
                throw new CryptoException("Invalid CertificateProfile format.");
            }

            _version = bR.ReadByte();
            switch (_version)
            {
            case 1:
                _flags    = (CertificateProfileFlags)bR.ReadUInt32();
                _verified = (CertificateProfileFlags)bR.ReadUInt32();

                if ((_flags & CertificateProfileFlags.Name) > 0)
                {
                    _name = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()));
                }

                if ((_flags & CertificateProfileFlags.Type) > 0)
                {
                    _type = (CertificateProfileType)bR.ReadByte();
                }

                if ((_flags & CertificateProfileFlags.EmailAddress) > 0)
                {
                    _emailAddress = new MailAddress(Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte())));
                }

                if ((_flags & CertificateProfileFlags.Website) > 0)
                {
                    _website = new Uri(Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte())));
                }

                if ((_flags & CertificateProfileFlags.PhoneNumber) > 0)
                {
                    _phoneNumber = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()));
                }

                if ((_flags & CertificateProfileFlags.StreetAddress) > 0)
                {
                    _streetAddress = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()));
                }

                if ((_flags & CertificateProfileFlags.City) > 0)
                {
                    _city = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()));
                }

                if ((_flags & CertificateProfileFlags.State) > 0)
                {
                    _state = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()));
                }

                if ((_flags & CertificateProfileFlags.Country) > 0)
                {
                    _country = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()));
                }

                if ((_flags & CertificateProfileFlags.PostalCode) > 0)
                {
                    _postalCode = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte()));
                }

                break;

            default:
                throw new CryptoException("CertificateProfile format version not supported.");
            }
        }