Files
odo/vendor/github.com/zalando/go-keyring/keyring_windows.go
dependabot[bot] 3d4f339e84 Go: Bump github.com/zalando/go-keyring from 0.2.1 to 0.2.3 (#7006)
Bumps [github.com/zalando/go-keyring](https://github.com/zalando/go-keyring) from 0.2.1 to 0.2.3.
- [Release notes](https://github.com/zalando/go-keyring/releases)
- [Commits](https://github.com/zalando/go-keyring/compare/v0.2.1...v0.2.3)

---
updated-dependencies:
- dependency-name: github.com/zalando/go-keyring
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-31 10:30:06 +02:00

70 lines
1.7 KiB
Go
Generated

package keyring
import (
"syscall"
"github.com/danieljoos/wincred"
)
type windowsKeychain struct{}
// Get gets a secret from the keyring given a service name and a user.
func (k windowsKeychain) Get(service, username string) (string, error) {
cred, err := wincred.GetGenericCredential(k.credName(service, username))
if err != nil {
if err == syscall.ERROR_NOT_FOUND {
return "", ErrNotFound
}
return "", err
}
return string(cred.CredentialBlob), nil
}
// Set stores stores user and pass in the keyring under the defined service
// name.
func (k windowsKeychain) Set(service, username, password string) error {
// password may not exceed 2560 bytes (https://github.com/jaraco/keyring/issues/540#issuecomment-968329967)
if len(password) > 2560 {
return ErrSetDataTooBig
}
// service may not exceed 512 bytes (might need more testing)
if len(service) >= 512 {
return ErrSetDataTooBig
}
// service may not exceed 32k but problems occur before that
// so we limit it to 30k
if len(service) > 1024*30 {
return ErrSetDataTooBig
}
cred := wincred.NewGenericCredential(k.credName(service, username))
cred.UserName = username
cred.CredentialBlob = []byte(password)
return cred.Write()
}
// Delete deletes a secret, identified by service & user, from the keyring.
func (k windowsKeychain) Delete(service, username string) error {
cred, err := wincred.GetGenericCredential(k.credName(service, username))
if err != nil {
if err == syscall.ERROR_NOT_FOUND {
return ErrNotFound
}
return err
}
return cred.Delete()
}
// credName combines service and username to a single string.
func (k windowsKeychain) credName(service, username string) string {
return service + ":" + username
}
func init() {
provider = windowsKeychain{}
}