github.com/cornelk/go-cloud@v0.17.1/secrets/driver/driver.go (about) 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 "github.com/cornelk/go-cloud/secrets/driver" 19 20 import ( 21 "context" 22 23 "github.com/cornelk/go-cloud/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 31 // Decrypt decrypts the ciphertext and returns the plaintext or an error. 32 // Decrypt *may* decrypt ciphertexts that were encrypted using a different 33 // key than the one provided to Keeper; some drivers encode the key used 34 // in the ciphertext. 35 Decrypt(ctx context.Context, ciphertext []byte) ([]byte, error) 36 37 // Encrypt encrypts the plaintext using the key, and returns the ciphertext. 38 Encrypt(ctx context.Context, plaintext []byte) ([]byte, error) 39 40 // Close releases any resources used for the Keeper. 41 Close() error 42 43 // ErrorAs allows drivers to expose driver-specific types for returned 44 // errors. 45 // 46 // See https://github.com/cornelk/go-cloud/concepts/as/ for background information. 47 ErrorAs(err error, i interface{}) bool 48 49 // ErrorCode should return a code that describes the error, which was returned 50 // by one of the other methods in this interface. 51 ErrorCode(error) gcerrors.ErrorCode 52 }