/// <summary> /// Initializes a new instance of the <see cref="KeyId" /> class. /// </summary> /// <param name="keyId">The key id.</param> /// <param name="fingerprint">The finger print.</param> /// <param name="allowedCapability">The allowed capability.</param> /// <param name="usableCapability">The usable capability.</param> /// <param name="userIds">The user ids.</param> public KeyId(string keyId, string fingerprint, KeyCapabilities allowedCapability, KeyCapabilities usableCapability, IEnumerable<string> userIds) { Id = keyId; Fingerprint = fingerprint; AllowedCapability = allowedCapability; UsableCapability = usableCapability; UserIds = userIds; }
/// <summary> /// Initializes a new instance of the <see cref="KeyId" /> class. /// </summary> /// <param name="keyId">The key id.</param> /// <param name="fingerprint">The finger print.</param> /// <param name="allowedCapability">The allowed capability.</param> /// <param name="usableCapability">The usable capability.</param> /// <param name="userIds">The user ids.</param> public KeyId(string keyId, string fingerprint, KeyCapabilities allowedCapability, KeyCapabilities usableCapability, IEnumerable <string> userIds) { Id = keyId; Fingerprint = fingerprint; AllowedCapability = allowedCapability; UsableCapability = usableCapability; UserIds = userIds; }
/// <summary>Called to verify that the key matches is allowed in the collection.</summary> protected void ValidateKey(KeyType key) { if(key == null) throw new ArgumentNullException(); PrimaryKey primaryKey = key as PrimaryKey; KeyCapabilities capabilities = primaryKey != null ? primaryKey.TotalCapabilities : key.Capabilities; if((capabilities & requiredCapabilities) != requiredCapabilities) { throw new ArgumentException("The key does not have all of the required capabilities: " + requiredCapabilities.ToString()); } }
/// <summary> /// Parses the key capability field from list keys command. /// </summary> /// <param name="field">The field.</param> /// <param name="allowed">The allowed.</param> /// <param name="usable">The usable.</param> static void ParseKeyCapField(string field, ref KeyCapabilities allowed, ref KeyCapabilities usable) { foreach (char c in field) { switch (c) { case 'e': allowed |= KeyCapabilities.Encrypt; break; case 'E': usable |= KeyCapabilities.Encrypt; break; case 's': allowed |= KeyCapabilities.Sign; break; case 'S': usable |= KeyCapabilities.Sign; break; case 'c': allowed |= KeyCapabilities.Certify; break; case 'C': usable |= KeyCapabilities.Certify; break; case 'a': allowed |= KeyCapabilities.Authentication; break; case 'A': usable |= KeyCapabilities.Authentication; break; case '?': allowed |= KeyCapabilities.Unknown; break; case 'D': usable |= KeyCapabilities.Disabled; break; } } }
/// <summary>Initializes a new <see cref="NewSubkeyForm"/> with the <see cref="PGPSystem"/> that will be used to /// create the subkey. /// </summary> public void Initialize(PGPSystem pgp) { if(pgp == null) throw new ArgumentNullException(); this.pgp = pgp; KeyCapabilities signOnly = KeyCapabilities.Sign; KeyCapabilities encryptOnly = KeyCapabilities.Encrypt; KeyCapabilities signAndEncrypt = signOnly | encryptOnly; bool supportsDSA = false, supportsELG = false, supportsRSA = false; foreach(string type in pgp.GetSupportedKeyTypes()) { if(!supportsDSA && string.Equals(type, PGP.KeyType.DSA, StringComparison.OrdinalIgnoreCase)) { supportsDSA = true; } else if(!supportsELG && string.Equals(type, PGP.KeyType.ElGamal, StringComparison.OrdinalIgnoreCase)) { supportsELG = true; } else if(!supportsRSA && string.Equals(type, PGP.KeyType.RSA, StringComparison.OrdinalIgnoreCase)) { supportsRSA = true; } } keyType.Items.Clear(); if(supportsELG) keyType.Items.Add(new KeyTypeItem(PGP.KeyType.ElGamal, encryptOnly, "El Gamal (encryption only)")); if(supportsRSA) keyType.Items.Add(new KeyTypeItem(PGP.KeyType.RSA, encryptOnly, "RSA (encryption only)")); if(supportsDSA) keyType.Items.Add(new KeyTypeItem(PGP.KeyType.DSA, signOnly, "DSA (signing only)")); if(supportsRSA) { keyType.Items.Add(new KeyTypeItem(PGP.KeyType.RSA, signOnly, "RSA (signing only)")); keyType.Items.Add(new KeyTypeItem(PGP.KeyType.RSA, signAndEncrypt, "RSA (sign and encrypt)")); } keyType.SelectedIndex = 0; // OpenPGP currently supports a maximum expiration date of February 25, 2174. we'll use the 24th to avoid // local <-> UTC conversion problems keyExpiration.MinDate = DateTime.Now.Date.AddDays(1); keyExpiration.MaxDate = new DateTime(2174, 2, 24, 0, 0, 0, DateTimeKind.Local); keyExpiration.Value = DateTime.UtcNow.Date.AddYears(5); // by default, the subkey expires in 5 years }
/// <summary>Initializes a new <see cref="KeyCollection{T}"/> with the given set of required key capabilities.</summary> public KeyCollection(KeyCapabilities requiredCapabilities) { this.requiredCapabilities = requiredCapabilities; }
/// <summary>Returns true if the <see cref="Key.Capabilities"/> property contains the given capability flags.</summary> public bool HasCapabilities(KeyCapabilities capability) { return (Capabilities & capability) == capability; }
public KeyTypeItem(string type, KeyCapabilities caps, string text) : base(new KeyTypeAndCapability(type, caps), text) { }
public KeyTypeAndCapability(string type, KeyCapabilities caps) { Type = type; Capabilities = caps; }