mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
6fde3632ef
The vendor/ folder was created with the help of @FiloSottile's gvt and vendorcheck. Any dependencies of Caddy plugins outside this repo are not vendored. We do not remove any unused, vendored packages because vendorcheck -u only checks using the current build configuration; i.e. packages that may be imported by files toggled by build tags of other systems. CI tests have been updated to ignore the vendor/ folder. When Go 1.9 is released, a few of the go commands should be revised to again use ./... as it will ignore the vendor folder by default.
48 lines
979 B
Go
48 lines
979 B
Go
package crypto
|
|
|
|
import (
|
|
"fmt"
|
|
"hash/fnv"
|
|
|
|
"github.com/hashicorp/golang-lru"
|
|
"github.com/lucas-clemente/quic-go/protocol"
|
|
)
|
|
|
|
var (
|
|
compressedCertsCache *lru.Cache
|
|
)
|
|
|
|
func getCompressedCert(chain [][]byte, pCommonSetHashes, pCachedHashes []byte) ([]byte, error) {
|
|
// Hash all inputs
|
|
hasher := fnv.New64a()
|
|
for _, v := range chain {
|
|
hasher.Write(v)
|
|
}
|
|
hasher.Write(pCommonSetHashes)
|
|
hasher.Write(pCachedHashes)
|
|
hash := hasher.Sum64()
|
|
|
|
var result []byte
|
|
|
|
resultI, isCached := compressedCertsCache.Get(hash)
|
|
if isCached {
|
|
result = resultI.([]byte)
|
|
} else {
|
|
var err error
|
|
result, err = compressChain(chain, pCommonSetHashes, pCachedHashes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
compressedCertsCache.Add(hash, result)
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func init() {
|
|
var err error
|
|
compressedCertsCache, err = lru.New(protocol.NumCachedCertificates)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("fatal error in quic-go: could not create lru cache: %s", err.Error()))
|
|
}
|
|
}
|