Mutable Keyset to allow modification and saving
Inheritance: IKeySet, IDisposable
Exemplo n.º 1
0
 public override int Run(string[] remainingArguments)
 {
     using (var keySet = new MutableKeySet(_location))
     {
         var status = keySet.Revoke(_version);
         if (!status)
         {
             Console.WriteLine("{0} {1}.", Localized.MsgCouldNotRevoke, _version);
             return -1;
         }
         try
         {
             if (keySet.Save(new KeySetWriter(_location, overwrite: true)))
             {
                 Console.WriteLine("{0} {1}.", Localized.MsgRevokedVersion, _version);
                 return 0;
             }
         }
         catch
         {
         }
         Console.WriteLine("{0} {1}.", Localized.MsgCouldNotWrite, _location);
         return -1;
     }
 }
Exemplo n.º 2
0
        public override int Run(string[] remainingArguments)
        {
            using (var keySet = new MutableKeySet(_location))
            {
                var status = keySet.Demote(_version);
                if (status == null)
                {
                    Console.WriteLine("{0} {1}", Localized.MsgUnknownVersion, _version);
                    return -1;
                }
                try
                {
                    if (keySet.Save(new KeySetWriter(_location, overwrite: true)))
                    {
                        Console.WriteLine(Localized.MsgDemotedVersion, _version, status);
                        return 0;
                    }
                }
                catch
                {
                }
            }

            Console.WriteLine("{0} {1}", Localized.MsgCouldNotWrite, _location);
            return -1;
        }
Exemplo n.º 3
0
        public override int Run(string[] remainingArguments)
        {
            var ret = 0;
            Crypter crypter = null;
            IKeySet ks = new KeySet(_location);

            Func<string> prompt = CachedPrompt.Password(Util.PromptForPassword).Prompt;

            IDisposable dks = null;
            if (!String.IsNullOrWhiteSpace(_crypterLocation))
            {
                if (_password)
                {
                    var cks = new PbeKeySet(_crypterLocation, prompt);
                    crypter = new Crypter(cks);
                    dks = cks;
                }
                else
                {
                    crypter = new Crypter(_crypterLocation);
                }
                ks = new EncryptedKeySet(ks, crypter);
            }
            else if (_password)
            {
                ks = new PbeKeySet(ks, prompt);
            }
            var d2ks = ks as IDisposable;

            using (crypter)
            using (dks)
            using (d2ks)
            using (var keySet = new MutableKeySet(ks))
            {
                var pubKeySet = keySet.PublicKey();
                if (pubKeySet != null)
                {
                    using (pubKeySet)
                    {
                        IKeySetWriter writer = new KeySetWriter(_destination, overwrite: false);

                        if (pubKeySet.Save(writer))
                        {
                            Console.WriteLine(Localized.MsgNewPublicKeySet);
                            ret = 0;
                        }
                        else
                        {
                            ret = -1;
                        }
                    }
                }
                else
                {
                    ret = -1;
                }
            }

            return ret;
        }