2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2019-01-23 17:31:34 +00:00
|
|
|
package keysutil
|
|
|
|
|
|
|
|
import (
|
2022-08-31 16:27:03 +00:00
|
|
|
"crypto"
|
2019-02-07 23:31:31 +00:00
|
|
|
"crypto/sha1"
|
2019-01-23 17:31:34 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
"crypto/sha512"
|
|
|
|
"hash"
|
2021-12-08 18:29:33 +00:00
|
|
|
|
|
|
|
"golang.org/x/crypto/sha3"
|
2019-01-23 17:31:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type HashType uint32
|
|
|
|
|
|
|
|
const (
|
2022-10-27 12:26:20 +00:00
|
|
|
HashTypeNone HashType = iota
|
|
|
|
HashTypeSHA1
|
2019-02-07 23:31:31 +00:00
|
|
|
HashTypeSHA2224
|
2019-01-23 17:31:34 +00:00
|
|
|
HashTypeSHA2256
|
|
|
|
HashTypeSHA2384
|
|
|
|
HashTypeSHA2512
|
2021-12-08 18:29:33 +00:00
|
|
|
HashTypeSHA3224
|
|
|
|
HashTypeSHA3256
|
|
|
|
HashTypeSHA3384
|
|
|
|
HashTypeSHA3512
|
2019-01-23 17:31:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MarshalingType uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ = iota
|
|
|
|
MarshalingTypeASN1 MarshalingType = iota
|
|
|
|
MarshalingTypeJWS
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
HashTypeMap = map[string]HashType{
|
2022-10-27 12:26:20 +00:00
|
|
|
"none": HashTypeNone,
|
2019-02-07 23:31:31 +00:00
|
|
|
"sha1": HashTypeSHA1,
|
2019-01-23 17:31:34 +00:00
|
|
|
"sha2-224": HashTypeSHA2224,
|
|
|
|
"sha2-256": HashTypeSHA2256,
|
|
|
|
"sha2-384": HashTypeSHA2384,
|
|
|
|
"sha2-512": HashTypeSHA2512,
|
2021-12-08 18:29:33 +00:00
|
|
|
"sha3-224": HashTypeSHA3224,
|
|
|
|
"sha3-256": HashTypeSHA3256,
|
|
|
|
"sha3-384": HashTypeSHA3384,
|
|
|
|
"sha3-512": HashTypeSHA3512,
|
2019-01-23 17:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HashFuncMap = map[HashType]func() hash.Hash{
|
2022-10-27 12:26:20 +00:00
|
|
|
HashTypeNone: nil,
|
2019-02-07 23:31:31 +00:00
|
|
|
HashTypeSHA1: sha1.New,
|
2019-01-23 17:31:34 +00:00
|
|
|
HashTypeSHA2224: sha256.New224,
|
|
|
|
HashTypeSHA2256: sha256.New,
|
|
|
|
HashTypeSHA2384: sha512.New384,
|
|
|
|
HashTypeSHA2512: sha512.New,
|
2021-12-08 18:29:33 +00:00
|
|
|
HashTypeSHA3224: sha3.New224,
|
|
|
|
HashTypeSHA3256: sha3.New256,
|
|
|
|
HashTypeSHA3384: sha3.New384,
|
|
|
|
HashTypeSHA3512: sha3.New512,
|
2019-01-23 17:31:34 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 16:27:03 +00:00
|
|
|
CryptoHashMap = map[HashType]crypto.Hash{
|
2022-10-27 12:26:20 +00:00
|
|
|
HashTypeNone: 0,
|
2022-08-31 16:27:03 +00:00
|
|
|
HashTypeSHA1: crypto.SHA1,
|
|
|
|
HashTypeSHA2224: crypto.SHA224,
|
|
|
|
HashTypeSHA2256: crypto.SHA256,
|
|
|
|
HashTypeSHA2384: crypto.SHA384,
|
|
|
|
HashTypeSHA2512: crypto.SHA512,
|
|
|
|
HashTypeSHA3224: crypto.SHA3_224,
|
|
|
|
HashTypeSHA3256: crypto.SHA3_256,
|
|
|
|
HashTypeSHA3384: crypto.SHA3_384,
|
|
|
|
HashTypeSHA3512: crypto.SHA3_512,
|
|
|
|
}
|
|
|
|
|
2019-01-23 17:31:34 +00:00
|
|
|
MarshalingTypeMap = map[string]MarshalingType{
|
|
|
|
"asn1": MarshalingTypeASN1,
|
|
|
|
"jws": MarshalingTypeJWS,
|
|
|
|
}
|
|
|
|
)
|