package webserver import ( "context" "crypto/x509" "encoding/pem" "errors" "google.golang.org/protobuf/types/known/structpb" ) 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 } // structFromMap converts a map[string]interface{} to a *structpb.Struct. func structFromMap(m map[string]interface{}) (*structpb.Struct, error) { return structpb.NewStruct(m) } // 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) }