github.com/opentofu/opentofu@v1.7.1/internal/encryption/method/errors.go (about)

     1  package method
     2  
     3  import "fmt"
     4  
     5  // ErrCryptoFailure indicates a generic cryptographic failure. This error should be embedded into
     6  // ErrEncryptionFailed, ErrDecryptionFailed, or ErrInvalidConfiguration.
     7  type ErrCryptoFailure struct {
     8  	Message string
     9  	Cause   error
    10  }
    11  
    12  func (e ErrCryptoFailure) Error() string {
    13  	if e.Cause != nil {
    14  		return fmt.Sprintf("%s: %v", e.Message, e.Cause)
    15  	}
    16  	return e.Message
    17  }
    18  
    19  func (e ErrCryptoFailure) Unwrap() error {
    20  	return e.Cause
    21  }
    22  
    23  // ErrEncryptionFailed indicates that encrypting a set of data failed.
    24  type ErrEncryptionFailed struct {
    25  	Cause error
    26  }
    27  
    28  func (e ErrEncryptionFailed) Error() string {
    29  	if e.Cause != nil {
    30  		return fmt.Sprintf("encryption failed: %v", e.Cause)
    31  	}
    32  	return "encryption failed"
    33  }
    34  
    35  func (e ErrEncryptionFailed) Unwrap() error {
    36  	return e.Cause
    37  }
    38  
    39  // ErrDecryptionFailed indicates that decrypting a set of data failed.
    40  type ErrDecryptionFailed struct {
    41  	Cause error
    42  }
    43  
    44  func (e ErrDecryptionFailed) Error() string {
    45  	if e.Cause != nil {
    46  		return fmt.Sprintf("decryption failed: %v", e.Cause)
    47  	}
    48  	return "decryption failed"
    49  }
    50  
    51  func (e ErrDecryptionFailed) Unwrap() error {
    52  	return e.Cause
    53  }
    54  
    55  // ErrDecryptionKeyUnavailable indicates that no decryption key is available.
    56  type ErrDecryptionKeyUnavailable struct {
    57  }
    58  
    59  func (e ErrDecryptionKeyUnavailable) Error() string {
    60  	return "no decryption key available"
    61  }
    62  
    63  // ErrInvalidConfiguration indicates that the method configuration is incorrect.
    64  type ErrInvalidConfiguration struct {
    65  	Cause error
    66  }
    67  
    68  func (e ErrInvalidConfiguration) Error() string {
    69  	if e.Cause != nil {
    70  		return fmt.Sprintf("invalid method configuration: %v", e.Cause)
    71  	}
    72  	return "invalid method configuration"
    73  }
    74  
    75  func (e ErrInvalidConfiguration) Unwrap() error {
    76  	return e.Cause
    77  }