github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/kbfscrypto/errors.go (about)

     1  // Copyright 2016 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package kbfscrypto
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/keybase/client/go/protocol/keybase1"
    11  )
    12  
    13  // InvalidKIDError is returned whenever an invalid KID is detected.
    14  type InvalidKIDError struct {
    15  	kid keybase1.KID
    16  }
    17  
    18  func (e InvalidKIDError) Error() string {
    19  	return fmt.Sprintf("Invalid KID %s", e.kid)
    20  }
    21  
    22  // InvalidByte32DataError is returned whenever invalid data for a
    23  // 32-byte type is detected.
    24  type InvalidByte32DataError struct {
    25  	data []byte
    26  }
    27  
    28  func (e InvalidByte32DataError) Error() string {
    29  	return fmt.Sprintf("Invalid byte32 data %v", e.data)
    30  }
    31  
    32  // UnknownSigVer indicates that we can't process a signature because
    33  // it has an unknown version.
    34  type UnknownSigVer struct {
    35  	Ver SigVer
    36  }
    37  
    38  // Error implements the error interface for UnknownSigVer
    39  func (e UnknownSigVer) Error() string {
    40  	return fmt.Sprintf("Unknown signature version %d", int(e.Ver))
    41  }
    42  
    43  // UnknownEncryptionVer indicates that we can't decrypt an
    44  // encryptedData object because it has an unknown version.
    45  type UnknownEncryptionVer struct {
    46  	Ver EncryptionVer
    47  }
    48  
    49  func (e UnknownEncryptionVer) Error() string {
    50  	return fmt.Sprintf("Unknown encryption version %d", int(e.Ver))
    51  }
    52  
    53  // InvalidEncryptionVer indicates that we can't decrypt an
    54  // encryptedData object because this data type doesn't support that
    55  // encryption version.
    56  type InvalidEncryptionVer struct {
    57  	Ver EncryptionVer
    58  }
    59  
    60  func (e InvalidEncryptionVer) Error() string {
    61  	return fmt.Sprintf("Invalid encryption version %d", int(e.Ver))
    62  }
    63  
    64  // InvalidNonceError indicates that an invalid cryptographic nonce was
    65  // detected.
    66  type InvalidNonceError struct {
    67  	Nonce []byte
    68  }
    69  
    70  func (e InvalidNonceError) Error() string {
    71  	return fmt.Sprintf("Invalid nonce %v", e.Nonce)
    72  }
    73  
    74  // PaddedBlockReadError occurs if the number of bytes read do not
    75  // equal the number of bytes specified.
    76  type PaddedBlockReadError struct {
    77  	ActualLen   int
    78  	ExpectedLen int
    79  }
    80  
    81  // Error implements the error interface of PaddedBlockReadError.
    82  func (e PaddedBlockReadError) Error() string {
    83  	return fmt.Sprintf("Reading block data out of padded block resulted in %d bytes, expected %d",
    84  		e.ActualLen, e.ExpectedLen)
    85  }