package webserver import ( "context" "crypto/x509" "encoding/pem" "errors" ) type contextKey int const tokenInfoCtxKey contextKey = iota func withTokenInfo(ctx context.Context, info *TokenInfo) context.Context { return context.WithValue(ctx, tokenInfoCtxKey, info) } func tokenInfoFromContext(ctx context.Context) *TokenInfo { v, _ := ctx.Value(tokenInfoCtxKey).(*TokenInfo) return v } // parsePEMCert decodes the first PEM block and parses it as an x509 certificate. func parsePEMCert(pemData []byte) (*x509.Certificate, error) { block, _ := pem.Decode(pemData) if block == nil { return nil, errors.New("no PEM block found") } return x509.ParseCertificate(block.Bytes) }