Skip to content

Commit 0cdb85d

Browse files
committed
Fixed bug on empty strings
1 parent bb7125f commit 0cdb85d

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

cmd/api/bitwarden.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020

2121
type bwCipher struct {
2222
Name string `json:"name,wrap"`
23-
Username string `json:"username,width:30"`
24-
URI string `json:"uri,width:40"`
23+
Username string `json:"username,width:30,wrap"`
24+
Password string `json:"password,width:30,wrap"`
25+
URI string `json:"uri,width:40,wrap"`
2526
Folder string `json:"folder,width:36"`
2627
}
2728

@@ -177,14 +178,28 @@ func bwLogins(w *tablewriter.Writer, _ []string) error {
177178
}
178179

179180
// Decrypt the ciphers from the session
180-
var result []*schema.Cipher
181+
var result []bwCipher
181182
for cipher := ciphers.Next(); cipher != nil; cipher = ciphers.Next() {
183+
if cipher.Type != schema.CipherTypeLogin || cipher.Login == nil {
184+
continue
185+
}
182186
if ciphers.CanCrypt() {
183187
if cipher, err := ciphers.Decrypt(cipher); err == nil {
184-
result = append(result, cipher)
188+
result = append(result, bwCipher{
189+
Name: cipher.Name,
190+
Username: cipher.Login.Username,
191+
Password: cipher.Login.Password,
192+
URI: cipher.Login.URI,
193+
Folder: cipher.FolderId,
194+
})
185195
}
186196
} else {
187-
result = append(result, cipher)
197+
result = append(result, bwCipher{
198+
Name: cipher.Name,
199+
Username: cipher.Login.Username,
200+
URI: cipher.Login.URI,
201+
Folder: cipher.FolderId,
202+
})
188203
}
189204
}
190205
return w.Write(result)

pkg/bitwarden/crypto/crypto.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ func (k *CryptoKey) Decrypt(data *Encrypted) ([]byte, error) {
184184
}
185185

186186
func (k *CryptoKey) DecryptStr(data string) (string, error) {
187-
if encrypted, err := NewEncrypted(data); err != nil {
187+
if data == "" {
188+
return "", nil
189+
} else if encrypted, err := NewEncrypted(data); err != nil {
188190
return "", err
189191
} else if value, err := k.Decrypt(encrypted); err != nil {
190192
return "", err

pkg/bitwarden/schema/cipher.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import (
1515
type Ciphers []*Cipher
1616

1717
type Cipher struct {
18-
Id string `json:"id"`
19-
Name string `json:"name"`
20-
Type CipherType `json:"type"`
21-
FolderId string `json:"folderId,omitempty"`
22-
OrganizationId string `json:"organizationId,omitempty"`
23-
Favorite bool `json:"favorite,omitempty"`
24-
Edit bool `json:"edit"`
25-
RevisionDate time.Time `json:"revisionDate"`
18+
Id string `json:"id,width:36"`
19+
Name string `json:"name,width:30"`
20+
Type CipherType `json:"type,width:5"`
21+
FolderId string `json:"folderId,omitempty,width:36"`
22+
OrganizationId string `json:"organizationId,omitempty,width:36"`
23+
Favorite bool `json:"favorite,omitempty,width:5"`
24+
Edit bool `json:"edit,width:5"`
25+
RevisionDate time.Time `json:"revisionDate,width:29"`
2626
CollectionIds []string `json:"collectionIds,omitempty"`
27-
ViewPassword bool `json:"viewPassword"`
27+
ViewPassword bool `json:"viewPassword,width:5"`
2828
Login *CipherLogin `json:"Login,omitempty,wrap"`
2929
// Card *CardData `json:"Card,omitempty"`
3030
// SecureNote *SecureNoteData `json:"SecureNote,omitempty"`

0 commit comments

Comments
 (0)