예제 #1
0
        public static PSObject CreateEntryResult(PwDatabase db, PwEntry passwordEntry, bool asUnprotectedStrings, bool resolveReferencedFields)
        {
            var result = new PSObject();

            result.AddProperty("Id", passwordEntry.Uuid.ToHexString());
            result.AddProperty("GroupName", passwordEntry.ParentGroup.Name);
            result.AddProperty("Path", passwordEntry.CreateGroupPath());
            result.AddPropertyIfNotNullOrEmpty(PwDefs.TitleField, GetStringEntry(PwDefs.TitleField, db, passwordEntry, asUnprotectedStrings, resolveReferencedFields));
            result.AddPropertyIfNotNullOrEmpty(PwDefs.UserNameField, GetStringEntry(PwDefs.UserNameField, db, passwordEntry, asUnprotectedStrings, resolveReferencedFields));
            result.AddProperty(PwDefs.PasswordField, asUnprotectedStrings ? (object)passwordEntry.Strings.Get(PwDefs.PasswordField).ReadString() : passwordEntry.Strings.Get(PwDefs.PasswordField).ReadUtf8().ToSecureString(Encoding.UTF8));
            result.AddProperty("EstimatedPasswordQualityBits", QualityEstimation.EstimatePasswordBits(passwordEntry.Strings.Get(PwDefs.PasswordField).ReadUtf8()));

            if (passwordEntry.Tags != null && passwordEntry.Tags.Any())
            {
                result.AddProperty("Tags", passwordEntry.Tags);
            }

            result.AddProperty("Expires", passwordEntry.Expires);
            if (passwordEntry.Expires)
            {
                result.AddProperty("IsExpired", passwordEntry.ExpiryTime < DateTime.Now);
                result.AddProperty("ExpireTime", passwordEntry.ExpiryTime);
            }

            foreach (var key1 in passwordEntry.Strings.GetKeys().Where(x => !new[] { PwDefs.TitleField, PwDefs.PasswordField, PwDefs.UserNameField }.Contains(x)))
            {
                result.AddPropertyIfNotNullOrEmpty(key1, GetStringEntry(key1, db, passwordEntry, asUnprotectedStrings, resolveReferencedFields));
            }
            // Version 2.36
            //foreach (var key1 in passwordEntry.CustomData)
            //{
            //    result.AddPropertyIfNotNullOrEmpty(key1.Key, key1.Value);
            //}
            return(result);
        }