Beispiel #1
0
        // internal AND protected
        internal override GpgInterfaceResult ProcessLine(String line)
        {
            String[] parts = line.Split(':');

            switch (parts[0])
            {
            case "pub":
            {
                Key key = new Key
                {
                    Trust          = GpgConvert.ToTrust(parts[1]),
                    Size           = Convert.ToUInt32(parts[2], CultureInfo.InvariantCulture),
                    Algorithm      = GpgConvert.ToKeyAlgorithm(parts[3]),
                    Id             = new KeyId(parts[4]),
                    CreationDate   = GpgConvert.ToDate(parts[5]),
                    ExpirationDate = new GpgDateTime(parts[6]),
                    OwnerTrust     = GpgConvert.ToOwnerTrust(parts[8]),
                    Type           = KeyType.Public
                };

                if (parts.Length > 11)
                {
                    String p = parts[11];
                    key.IsDisabled = p.Contains("D");
                }

                Keys.Add(key);
                _lastKey = key;
                _index   = 1;
                break;
            }

            case "fpr":
            {
                _lastKey.FingerPrint = new FingerPrint(parts[9]);
                break;
            }

            case "sub":
            {
                KeySub sub = new KeySub
                {
                    Trust          = GpgConvert.ToTrust(parts[1]),
                    Size           = Convert.ToUInt32(parts[2], CultureInfo.InvariantCulture),
                    Algorithm      = GpgConvert.ToKeyAlgorithm(parts[3]),
                    Id             = new KeyId(parts[4]),
                    CreationDate   = GpgConvert.ToDate(parts[5]),
                    ExpirationDate = new GpgDateTime(parts[6])
                };

                if (parts.Length > 11)
                {
                    String p = parts[11];
                    sub.IsDisabled = p.Contains("D");
                }

                _lastKey.SubKeys.Add(sub);
                _lastKeyNode = sub;
                break;
            }

            case "uat":
            {
                if (parts.Length >= 6)
                {
                    KeyPhoto photo = new KeyPhoto
                    {
                        Index = _index++
                    };

                    _lastKey.Photos.Add(photo);
                    _lastKeyNode = photo;
                }
                break;
            }

            case "uid":
            {
                KeyUserInfo userid = new KeyUserInfo(Utils.UnescapeGpgString(parts[9]))
                {
                    Index = _index++
                };

                _lastKey.UserInfos.Add(userid);
                _lastKeyNode = userid;
                break;
            }

            case "sig":
            case "rev":
            {
                if (_lastKeyNode != null)
                {
                    _lastKeyNode.Signatures.Add(new KeySignature(parts[4], GpgConvert.ToDate(parts[5]), String.Equals(parts[0], "rev", StringComparison.Ordinal)));
                }
                break;
            }
            }

            return(GpgInterfaceResult.Success);
        }
        // internal AND protected
        internal override GpgInterfaceResult ProcessLine(String line)
        {
            String[] parts = line.Split(':');

            switch (parts[0])
            {
                case "pub":
                {
                    Key key = new Key
                    {
                        Trust = GpgConvert.ToTrust(parts[1]),
                        Size = Convert.ToUInt32(parts[2], CultureInfo.InvariantCulture),
                        Algorithm = GpgConvert.ToKeyAlgorithm(parts[3]),
                        Id = new KeyId(parts[4]),
                        CreationDate = GpgConvert.ToDate(parts[5]),
                        ExpirationDate = new GpgDateTime(parts[6]),
                        OwnerTrust = GpgConvert.ToOwnerTrust(parts[8]),
                        Type = KeyType.Public
                    };

                    if (parts.Length > 11)
                    {
                        String p = parts[11];
                        key.IsDisabled = p.Contains("D");
                    }

                    Keys.Add(key);
                    _lastKey = key;
                    _index = 1;
                    break;
                }

                case "fpr":
                {
                    _lastKey.FingerPrint = new FingerPrint(parts[9]);
                    break;
                }

                case "sub":
                {
                    KeySub sub = new KeySub
                    {
                        Trust = GpgConvert.ToTrust(parts[1]),
                        Size = Convert.ToUInt32(parts[2], CultureInfo.InvariantCulture),
                        Algorithm = GpgConvert.ToKeyAlgorithm(parts[3]),
                        Id = new KeyId(parts[4]),
                        CreationDate = GpgConvert.ToDate(parts[5]),
                        ExpirationDate = new GpgDateTime(parts[6])
                    };

                    if (parts.Length > 11)
                    {
                        String p = parts[11];
                        sub.IsDisabled = p.Contains("D");
                    }

                    _lastKey.SubKeys.Add(sub);
                    _lastKeyNode = sub;
                    break;
                }

                case "uat":
                {
                    if (parts.Length >= 6)
                    {
                        KeyPhoto photo = new KeyPhoto
                        {
                            Index = _index++
                        };

                        _lastKey.Photos.Add(photo);
                        _lastKeyNode = photo;
                    }
                    break;
                }

                case "uid":
                {
                    KeyUserInfo userid = new KeyUserInfo(Utils.UnescapeGpgString(parts[9]))
                    {
                        Index = _index++
                    };

                    _lastKey.UserInfos.Add(userid);
                    _lastKeyNode = userid;
                    break;
                }

                case "sig":
                case "rev":
                {
                    if (_lastKeyNode != null)
                        _lastKeyNode.Signatures.Add(new KeySignature(parts[4], GpgConvert.ToDate(parts[5]), String.Equals(parts[0], "rev", StringComparison.Ordinal)));
                    break;
                }
            }

            return GpgInterfaceResult.Success;
        }