mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
crypto/x509: use unsafe.Slice
Change-Id: I40fdfbd5cfb9f5ccb80d55bca28ff9ba1ec490f3 Reviewed-on: https://go-review.googlesource.com/c/go/+/435285 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
7398c3c0c6
commit
a451713286
|
@ -30,7 +30,7 @@ type CFRef uintptr
|
|||
func CFDataToSlice(data CFRef) []byte {
|
||||
length := CFDataGetLength(data)
|
||||
ptr := CFDataGetBytePtr(data)
|
||||
src := (*[1 << 20]byte)(unsafe.Pointer(ptr))[:length:length]
|
||||
src := unsafe.Slice((*byte)(unsafe.Pointer(ptr)), length)
|
||||
out := make([]byte, length)
|
||||
copy(out, src)
|
||||
return out
|
||||
|
|
|
@ -69,13 +69,13 @@ func extractSimpleChain(simpleChain **syscall.CertSimpleChain, count int) (chain
|
|||
return nil, errors.New("x509: invalid simple chain")
|
||||
}
|
||||
|
||||
simpleChains := (*[1 << 20]*syscall.CertSimpleChain)(unsafe.Pointer(simpleChain))[:count:count]
|
||||
simpleChains := unsafe.Slice(simpleChain, count)
|
||||
lastChain := simpleChains[count-1]
|
||||
elements := (*[1 << 20]*syscall.CertChainElement)(unsafe.Pointer(lastChain.Elements))[:lastChain.NumElements:lastChain.NumElements]
|
||||
elements := unsafe.Slice(lastChain.Elements, lastChain.NumElements)
|
||||
for i := 0; i < int(lastChain.NumElements); i++ {
|
||||
// Copy the buf, since ParseCertificate does not create its own copy.
|
||||
cert := elements[i].CertContext
|
||||
encodedCert := (*[1 << 20]byte)(unsafe.Pointer(cert.EncodedCert))[:cert.Length:cert.Length]
|
||||
encodedCert := unsafe.Slice(cert.EncodedCert, cert.Length)
|
||||
buf := make([]byte, cert.Length)
|
||||
copy(buf, encodedCert)
|
||||
parsedCert, err := ParseCertificate(buf)
|
||||
|
@ -258,8 +258,7 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
|
|||
}
|
||||
|
||||
if lqCtxCount := topCtx.LowerQualityChainCount; lqCtxCount > 0 {
|
||||
lqCtxs := (*[1 << 20]*syscall.CertChainContext)(unsafe.Pointer(topCtx.LowerQualityChains))[:lqCtxCount:lqCtxCount]
|
||||
|
||||
lqCtxs := unsafe.Slice(topCtx.LowerQualityChains, lqCtxCount)
|
||||
for _, ctx := range lqCtxs {
|
||||
chain, err := verifyChain(c, ctx, opts)
|
||||
if err == nil {
|
||||
|
|
Loading…
Reference in a new issue