Пример #1
0
        public CipherMiniResponseModel(Cipher cipher, GlobalSettings globalSettings, bool orgUseTotp, string obj = "cipherMini")
            : base(obj)
        {
            if (cipher == null)
            {
                throw new ArgumentNullException(nameof(cipher));
            }

            Id                  = cipher.Id.ToString();
            Type                = cipher.Type;
            RevisionDate        = cipher.RevisionDate;
            OrganizationId      = cipher.OrganizationId?.ToString();
            Attachments         = AttachmentResponseModel.FromCipher(cipher, globalSettings);
            OrganizationUseTotp = orgUseTotp;

            switch (cipher.Type)
            {
            case Enums.CipherType.Login:
                Data = new LoginDataModel(cipher);
                break;

            case Enums.CipherType.SecureNote:
                Data = new SecureNoteDataModel(cipher);
                break;

            case Enums.CipherType.Card:
                Data = new CardDataModel(cipher);
                break;

            default:
                throw new ArgumentException("Unsupported " + nameof(Type) + ".");
            }
        }
Пример #2
0
        public LoginResponseModel(Cipher cipher, GlobalSettings globalSettings, bool orgUseTotp, string obj = "login")
            : base(obj)
        {
            if (cipher == null)
            {
                throw new ArgumentNullException(nameof(cipher));
            }

            if (cipher.Type != Enums.CipherType.Login)
            {
                throw new ArgumentException(nameof(cipher.Type));
            }

            var data = new LoginDataModel(cipher);

            Id                  = cipher.Id.ToString();
            OrganizationId      = cipher.OrganizationId?.ToString();
            Name                = data.Name;
            Uri                 = data.Uri;
            Username            = data.Username;
            Password            = data.Password;
            Notes               = data.Notes;
            Totp                = data.Totp;
            RevisionDate        = cipher.RevisionDate;
            Edit                = true;
            OrganizationUseTotp = orgUseTotp;
            Attachments         = AttachmentResponseModel.FromCipher(cipher, globalSettings);
        }
Пример #3
0
        public CipherMiniResponseModel(Cipher cipher, GlobalSettings globalSettings, bool orgUseTotp, string obj = "cipherMini")
            : base(obj)
        {
            if (cipher == null)
            {
                throw new ArgumentNullException(nameof(cipher));
            }

            Id   = cipher.Id.ToString();
            Type = cipher.Type;

            CipherData cipherData;

            switch (cipher.Type)
            {
            case Enums.CipherType.Login:
                var loginData = JsonConvert.DeserializeObject <CipherLoginData>(cipher.Data);
                cipherData = loginData;
                Data       = loginData;
                Login      = new CipherLoginModel(loginData);
                break;

            case Enums.CipherType.SecureNote:
                var secureNoteData = JsonConvert.DeserializeObject <CipherSecureNoteData>(cipher.Data);
                Data       = secureNoteData;
                cipherData = secureNoteData;
                SecureNote = new CipherSecureNoteModel(secureNoteData);
                break;

            case Enums.CipherType.Card:
                var cardData = JsonConvert.DeserializeObject <CipherCardData>(cipher.Data);
                Data       = cardData;
                cipherData = cardData;
                Card       = new CipherCardModel(cardData);
                break;

            case Enums.CipherType.Identity:
                var identityData = JsonConvert.DeserializeObject <CipherIdentityData>(cipher.Data);
                Data       = identityData;
                cipherData = identityData;
                Identity   = new CipherIdentityModel(identityData);
                break;

            default:
                throw new ArgumentException("Unsupported " + nameof(Type) + ".");
            }

            Name                = cipherData.Name;
            Notes               = cipherData.Notes;
            Fields              = cipherData.Fields?.Select(f => new CipherFieldModel(f));
            PasswordHistory     = cipherData.PasswordHistory?.Select(ph => new CipherPasswordHistoryModel(ph));
            RevisionDate        = cipher.RevisionDate;
            OrganizationId      = cipher.OrganizationId?.ToString();
            Attachments         = AttachmentResponseModel.FromCipher(cipher, globalSettings);
            OrganizationUseTotp = orgUseTotp;
            DeletedDate         = cipher.DeletedDate;
            Reprompt            = cipher.Reprompt.GetValueOrDefault(CipherRepromptType.None);
        }