Skip to content

Commit

Permalink
use byte slice instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
peterguy committed Sep 13, 2024
1 parent 0c47790 commit da9f04e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/token/secure_storage_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ type Token struct {
Account string
}

func (t *Token) Save(tokenValue string) error {
func (t *Token) Save(token []byte) error {

if existing_token, err := t.Retrieve(service, username); err == nil {
if existing_token, err := t.Retrieve(); err == nil {
if bytes.Equal(token, existing_token) {
// the stored token and supplied token are the same
// nothing to do
return nil
}
// found a token, but it is different from the supplied token, so update the token
return keychain.UpdateItem(buildItem(service, username, nil), buildItem(service, username, token))
return keychain.UpdateItem(buildItem(t.Service, t.Account, nil), buildItem(t.Service, t.Account, token))
} else if err != keychain.ErrorItemNotFound {
// encountered an error checking for the token; bail now
return err
}

item := buildItem(service, username, token)
item := buildItem(t.Service, t.Account, token)
if err := keychain.AddItem(item); err != nil {
if err == keychain.ErrorDuplicateItem {
// silently skip duplicates
Expand All @@ -42,7 +42,7 @@ func (t *Token) Save(tokenValue string) error {
}

func (t *Token) Retrieve() ([]byte, error) {
query := buildItem(service, username, nil)
query := buildItem(t.Service, t.Account, nil)
query.SetMatchLimit(keychain.MatchLimitOne)
query.SetReturnData(true)
results, err := keychain.QueryItem(query)
Expand Down

0 comments on commit da9f04e

Please sign in to comment.