refactor: Use simpler error messages
This commit is contained in:
@@ -135,7 +135,7 @@ var archiveCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(hdrs) <= i-1 {
|
if len(hdrs) <= i-1 {
|
||||||
return config.ErrMissingTarHeader
|
return config.ErrTarHeaderMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
*hdr = *hdrs[i-1]
|
*hdr = *hdrs[i-1]
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ var updateCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(hdrs) <= i-1 {
|
if len(hdrs) <= i-1 {
|
||||||
return config.ErrMissingTarHeader
|
return config.ErrTarHeaderMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
*hdr = *hdrs[i-1]
|
*hdr = *hdrs[i-1]
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func Compress(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !isRegular {
|
if !isRegular {
|
||||||
return nil, config.ErrCompressionFormatOnlyRegularSupport // "device or resource busy"
|
return nil, config.ErrCompressionFormatRegularOnly // "device or resource busy"
|
||||||
}
|
}
|
||||||
|
|
||||||
l := pgzip.DefaultCompression
|
l := pgzip.DefaultCompression
|
||||||
@@ -131,7 +131,7 @@ func Compress(
|
|||||||
return zz, nil
|
return zz, nil
|
||||||
case config.CompressionFormatBrotliKey:
|
case config.CompressionFormatBrotliKey:
|
||||||
if !isRegular {
|
if !isRegular {
|
||||||
return nil, config.ErrCompressionFormatOnlyRegularSupport // "cannot allocate memory"
|
return nil, config.ErrCompressionFormatRegularOnly // "cannot allocate memory"
|
||||||
}
|
}
|
||||||
|
|
||||||
l := brotli.DefaultCompression
|
l := brotli.DefaultCompression
|
||||||
|
|||||||
@@ -60,12 +60,12 @@ func DecryptHeader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if hdr.PAXRecords == nil {
|
if hdr.PAXRecords == nil {
|
||||||
return config.ErrEmbeddedHeaderMissing
|
return config.ErrTarHeaderEmbeddedMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
encryptedEmbeddedHeader, ok := hdr.PAXRecords[records.STFSRecordEmbeddedHeader]
|
encryptedEmbeddedHeader, ok := hdr.PAXRecords[records.STFSRecordEmbeddedHeader]
|
||||||
if !ok {
|
if !ok {
|
||||||
return config.ErrEmbeddedHeaderMissing
|
return config.ErrTarHeaderEmbeddedMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
embeddedHeader, err := DecryptString(encryptedEmbeddedHeader, encryptionFormat, identity)
|
embeddedHeader, err := DecryptString(encryptedEmbeddedHeader, encryptionFormat, identity)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package records
|
package records
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
STFSPrefix = "STFS."
|
STFSPrefix = "STFS."
|
||||||
|
|
||||||
@@ -25,8 +23,3 @@ const (
|
|||||||
|
|
||||||
STFSRecordEmbeddedHeader = STFSPrefix + "EmbeddedHeader"
|
STFSRecordEmbeddedHeader = STFSPrefix + "EmbeddedHeader"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrUnsupportedVersion = errors.New("unsupported STFS version")
|
|
||||||
ErrUnsupportedAction = errors.New("unsupported STFS action")
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func Sign(
|
|||||||
switch signatureFormat {
|
switch signatureFormat {
|
||||||
case config.SignatureFormatMinisignKey:
|
case config.SignatureFormatMinisignKey:
|
||||||
if !isRegular {
|
if !isRegular {
|
||||||
return nil, nil, config.ErrSignatureFormatOnlyRegularSupport
|
return nil, nil, config.ErrSignatureFormatRegularOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
identity, ok := identity.(minisign.PrivateKey)
|
identity, ok := identity.(minisign.PrivateKey)
|
||||||
@@ -126,7 +126,7 @@ func SignString(
|
|||||||
switch signatureFormat {
|
switch signatureFormat {
|
||||||
case config.SignatureFormatMinisignKey:
|
case config.SignatureFormatMinisignKey:
|
||||||
if !isRegular {
|
if !isRegular {
|
||||||
return "", config.ErrSignatureFormatOnlyRegularSupport
|
return "", config.ErrSignatureFormatRegularOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
identity, ok := identity.(minisign.PrivateKey)
|
identity, ok := identity.(minisign.PrivateKey)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func Verify(
|
|||||||
switch signatureFormat {
|
switch signatureFormat {
|
||||||
case config.SignatureFormatMinisignKey:
|
case config.SignatureFormatMinisignKey:
|
||||||
if !isRegular {
|
if !isRegular {
|
||||||
return nil, nil, config.ErrSignatureFormatOnlyRegularSupport
|
return nil, nil, config.ErrSignatureFormatRegularOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
recipient, ok := recipient.(minisign.PublicKey)
|
recipient, ok := recipient.(minisign.PublicKey)
|
||||||
@@ -99,12 +99,12 @@ func VerifyHeader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if hdr.PAXRecords == nil {
|
if hdr.PAXRecords == nil {
|
||||||
return config.ErrEmbeddedHeaderMissing
|
return config.ErrTarHeaderEmbeddedMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
embeddedHeader, ok := hdr.PAXRecords[records.STFSRecordEmbeddedHeader]
|
embeddedHeader, ok := hdr.PAXRecords[records.STFSRecordEmbeddedHeader]
|
||||||
if !ok {
|
if !ok {
|
||||||
return config.ErrEmbeddedHeaderMissing
|
return config.ErrTarHeaderEmbeddedMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
signature, ok := hdr.PAXRecords[records.STFSRecordSignature]
|
signature, ok := hdr.PAXRecords[records.STFSRecordSignature]
|
||||||
@@ -136,7 +136,7 @@ func VerifyString(
|
|||||||
switch signatureFormat {
|
switch signatureFormat {
|
||||||
case config.SignatureFormatMinisignKey:
|
case config.SignatureFormatMinisignKey:
|
||||||
if !isRegular {
|
if !isRegular {
|
||||||
return config.ErrSignatureFormatOnlyRegularSupport
|
return config.ErrSignatureFormatRegularOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
recipient, ok := recipient.(minisign.PublicKey)
|
recipient, ok := recipient.(minisign.PublicKey)
|
||||||
|
|||||||
@@ -3,30 +3,33 @@ package config
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrEncryptionFormatUnknown = errors.New("unknown encryption format")
|
ErrEncryptionFormatUnknown = errors.New("encryption format unknown")
|
||||||
ErrEncryptionFormatUnsupported = errors.New("unsupported encryption format")
|
ErrSignatureFormatUnknown = errors.New("signature format unknown")
|
||||||
|
ErrCompressionFormatUnknown = errors.New("compression format unknown")
|
||||||
|
|
||||||
|
ErrEncryptionFormatUnsupported = errors.New("encryption format unsupported")
|
||||||
|
ErrSignatureFormatUnsupported = errors.New("signature format unsupported")
|
||||||
|
ErrCompressionFormatUnsupported = errors.New("compression format unsupported")
|
||||||
|
|
||||||
|
ErrSignatureFormatRegularOnly = errors.New("signature format only supports regular files, not tape drives")
|
||||||
|
ErrSignatureInvalid = errors.New("signature invalid")
|
||||||
|
ErrSignatureMissing = errors.New("signature missing")
|
||||||
|
|
||||||
|
ErrCompressionFormatRegularOnly = errors.New("compression format only supports regular files, not tape drives")
|
||||||
|
ErrCompressionFormatRequiresLargerRecordSize = errors.New("compression format requires larger record size")
|
||||||
|
ErrCompressionLevelUnsupported = errors.New("compression level unsupported")
|
||||||
|
ErrCompressionLevelUnknown = errors.New("compression level unknown")
|
||||||
|
|
||||||
ErrIdentityUnparsable = errors.New("identity could not be parsed")
|
ErrIdentityUnparsable = errors.New("identity could not be parsed")
|
||||||
ErrRecipientUnparsable = errors.New("recipient could not be parsed")
|
ErrRecipientUnparsable = errors.New("recipient could not be parsed")
|
||||||
|
|
||||||
ErrEmbeddedHeaderMissing = errors.New("embedded header is missing")
|
ErrKeygenFormatUnsupported = errors.New("key generation for format unsupported")
|
||||||
|
|
||||||
ErrSignatureFormatUnknown = errors.New("unknown signature format")
|
ErrTarHeaderMissing = errors.New("tar header missing")
|
||||||
ErrSignatureFormatUnsupported = errors.New("unsupported signature format")
|
ErrTarHeaderEmbeddedMissing = errors.New("embedded tar header missing")
|
||||||
ErrSignatureFormatOnlyRegularSupport = errors.New("this signature format only supports regular files, not i.e. tape drives")
|
|
||||||
ErrSignatureInvalid = errors.New("signature is invalid")
|
|
||||||
ErrSignatureMissing = errors.New("signature is missing")
|
|
||||||
|
|
||||||
ErrKeygenForFormatUnsupported = errors.New("can not generate keys for this format")
|
ErrTapeDrivesUnsupported = errors.New("system unsupported for tape drives")
|
||||||
|
|
||||||
ErrCompressionFormatUnknown = errors.New("unknown compression format")
|
ErrSTFSVersionUnsupported = errors.New("STFS version unsupported")
|
||||||
ErrCompressionFormatUnsupported = errors.New("unsupported compression format")
|
ErrSTFSActionUnsupported = errors.New("STFS action unsupported")
|
||||||
ErrCompressionFormatOnlyRegularSupport = errors.New("this compression format only supports regular files, not i.e. tape drives")
|
|
||||||
ErrCompressionFormatRequiresLargerRecordSize = errors.New("this compression format requires a larger record size")
|
|
||||||
ErrCompressionLevelUnsupported = errors.New("compression level is unsupported")
|
|
||||||
ErrCompressionLevelUnknown = errors.New("unknown compression level")
|
|
||||||
|
|
||||||
ErrMissingTarHeader = errors.New("tar header is missing")
|
|
||||||
|
|
||||||
ErrDrivesUnsupported = errors.New("this system does not support tape drives")
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func Delete(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(hdrs) <= i-1 {
|
if len(hdrs) <= i-1 {
|
||||||
return config.ErrMissingTarHeader
|
return config.ErrTarHeaderMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
*hdr = *hdrs[i-1]
|
*hdr = *hdrs[i-1]
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ func Move(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(hdrs) <= i-1 {
|
if len(hdrs) <= i-1 {
|
||||||
return config.ErrMissingTarHeader
|
return config.ErrTarHeaderMissing
|
||||||
}
|
}
|
||||||
|
|
||||||
*hdr = *hdrs[i-1]
|
*hdr = *hdrs[i-1]
|
||||||
|
|||||||
@@ -360,10 +360,10 @@ func indexHeader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return records.ErrUnsupportedAction
|
return config.ErrSTFSActionUnsupported
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return records.ErrUnsupportedVersion
|
return config.ErrSTFSVersionUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func Keygen(
|
|||||||
privkey = priv
|
privkey = priv
|
||||||
pubkey = pub
|
pubkey = pub
|
||||||
} else {
|
} else {
|
||||||
return []byte{}, []byte{}, config.ErrKeygenForFormatUnsupported
|
return []byte{}, []byte{}, config.ErrKeygenFormatUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
return privkey, pubkey, nil
|
return privkey, pubkey, nil
|
||||||
@@ -106,7 +106,7 @@ func generateEncryptionKey(
|
|||||||
|
|
||||||
return priv, pub, nil
|
return priv, pub, nil
|
||||||
default:
|
default:
|
||||||
return []byte{}, []byte{}, config.ErrKeygenForFormatUnsupported
|
return []byte{}, []byte{}, config.ErrKeygenFormatUnsupported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +130,6 @@ func generateSignatureKey(
|
|||||||
case config.SignatureFormatPGPKey:
|
case config.SignatureFormatPGPKey:
|
||||||
return generateEncryptionKey(signatureFormat, password)
|
return generateEncryptionKey(signatureFormat, password)
|
||||||
default:
|
default:
|
||||||
return []byte{}, []byte{}, config.ErrKeygenForFormatUnsupported
|
return []byte{}, []byte{}, config.ErrKeygenFormatUnsupported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user