private void Load(PgpPublicKey key) { this.KeyId = key.KeyId.ToString("X"); if (this.KeyId != null && this.KeyId.Length >= 15) { this.KeyIdShort = this.KeyId.Substring(this.KeyId.Length - 8); } this.Algorithm = key.Algorithm.ToString(); this.BitStrength = key.BitStrength; this.IsMasterKey = key.IsMasterKey; this.IsEncryptionKey = key.IsEncryptionKey; this.Version = key.Version; this.CreatedOnUtc = key.CreationTime.ToUniversalTime(); var validForSeconds = key.GetValidSeconds(); if (validForSeconds > 0) { this.Expires = this.CreatedOnUtc.Value.AddSeconds(validForSeconds); } //this.ValidDays = key.ValidDays; //if (this.ValidDays.HasValue) //{ // this.Expires = this.CreatedOnUtc.Value.AddDays(this.ValidDays.Value); //} //else //{ // this.Expires = null; //} try { var userIds = key.GetUserIds(); if (userIds != null) { var enumerator = userIds.GetEnumerator(); if (enumerator.MoveNext()) { var userIdentity = enumerator.Current as string; if (userIdentity != null && userIdentity.Contains("<") && userIdentity.Contains(">")) { var name = userIdentity.Substring(0, userIdentity.IndexOf("<") - 1).Trim(); this.IdentityName = name; var email = userIdentity.Substring(userIdentity.IndexOf("<") + 1); email = email.Substring(0, email.IndexOf(">")).Trim(); this.IdentityEmail = email; } } } } catch { } }
internal static void InvokeLambda( ISignaler signaler, Node lambda, PgpPublicKey key) { // Parametrizing [.lambda] callback with key and data. var keyNode = new Node(".key"); keyNode.Add(new Node("private", false)); keyNode.Add(new Node("fingerprint", PgpHelpers.GetFingerprint(key))); keyNode.Add(new Node("id", key.KeyId)); keyNode.Add(new Node("content", PgpHelpers.GetAsciiArmoredPublicKey(key))); keyNode.Add(new Node("created", key.CreationTime)); keyNode.Add(new Node("valid-seconds", key.GetValidSeconds())); keyNode.Add(new Node("algorithm", key.Algorithm.ToString())); keyNode.Add(new Node("bit-strength", key.BitStrength)); keyNode.Add(new Node("is-encryption", key.IsEncryptionKey)); keyNode.Add(new Node("is-master", key.IsMasterKey)); keyNode.Add(new Node("is-revoked", key.IsRevoked())); // Adding ID for key. var ids = new Node("ids"); foreach (var idxId in key.GetUserIds()) { ids.Add(new Node(".", idxId.ToString())); } if (ids.Children.Any()) { keyNode.Add(ids); } // Invoking [.lambda] making sure we reset it after evaluation. var exe = lambda.Clone(); lambda.Insert(0, keyNode); signaler.Signal("eval", lambda); lambda.Clear(); lambda.AddRange(exe.Children.ToList()); }