| 1 |
// Copyright 2018 The Go Cloud Development Kit Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
// Package driver defines interfaces to be implemented by secrets drivers, which |
| 16 |
// will be used by the secrets package to interact with the underlying services. |
| 17 |
// Application code should use package secrets. |
| 18 |
package driver // import "gocloud.dev/secrets/driver" |
| 19 |
|
| 20 |
import ( |
| 21 |
"context" |
| 22 |
|
| 23 |
"gocloud.dev/gcerrors" |
| 24 |
) |
| 25 |
|
| 26 |
// Keeper holds the key information to encrypt a plain text message into a |
| 27 |
// cipher message, as well as decrypt a cipher message into a plain text |
| 28 |
// message. |
| 29 |
type Keeper interface { |
| 30 |
// Decrypt decrypts the ciphertext and returns the plaintext or an error. |
| 31 |
// Decrypt *may* decrypt ciphertexts that were encrypted using a different |
| 32 |
// key than the one provided to Keeper; some drivers encode the key used |
| 33 |
// in the ciphertext. |
| 34 |
Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) |
| 35 |
|
| 36 |
// Encrypt encrypts the plaintext using the key, and returns the ciphertext. |
| 37 |
Encrypt(ctx context.Context, plaintext []byte) ([]byte, error) |
| 38 |
|
| 39 |
// Close releases any resources used for the Keeper. |
| 40 |
Close() error |
| 41 |
|
| 42 |
// ErrorAs allows drivers to expose driver-specific types for returned |
| 43 |
// errors. |
| 44 |
// |
| 45 |
// See https://gocloud.dev/concepts/as/ for background information. |
| 46 |
ErrorAs(err error, i any) bool |
| 47 |
|
| 48 |
// ErrorCode should return a code that describes the error, which was returned |
| 49 |
// by one of the other methods in this interface. |
| 50 |
ErrorCode(error) gcerrors.ErrorCode |
| 51 |
} |