github.com/zntrio/harp/v2@v2.0.9/pkg/sdk/value/signature/context.go (about) 1 // Licensed to Elasticsearch B.V. under one or more contributor 2 // license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright 4 // ownership. Elasticsearch B.V. licenses this file to you under 5 // the Apache License, Version 2.0 (the "License"); you may 6 // not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 package signature 19 20 import ( 21 "context" 22 ) 23 24 var ( 25 contextKeyDetachedSignature = contextKey("detachedSignature") 26 contextKeyInputHash = contextKey("inputHash") 27 contextKeyDeterministicSignature = contextKey("deterministic") 28 ) 29 30 // ----------------------------------------------------------------------------- 31 32 type contextKey string 33 34 func (c contextKey) String() string { 35 return "github.com/zntrio/harp/v2/pkg/sdk/value/signature/" + string(c) 36 } 37 38 // ----------------------------------------------------------------------------- 39 40 func WithDetachedSignature(ctx context.Context, value bool) context.Context { 41 return context.WithValue(ctx, contextKeyDetachedSignature, value) 42 } 43 44 func IsDetached(ctx context.Context) bool { 45 value, ok := ctx.Value(contextKeyDetachedSignature).(bool) 46 if !ok { 47 return false 48 } 49 return value 50 } 51 52 func WithInputPreHashed(ctx context.Context, value bool) context.Context { 53 return context.WithValue(ctx, contextKeyInputHash, value) 54 } 55 56 func IsInputPreHashed(ctx context.Context) bool { 57 value, ok := ctx.Value(contextKeyInputHash).(bool) 58 if !ok { 59 return false 60 } 61 return value 62 } 63 64 func WithDetermisticSignature(ctx context.Context, value bool) context.Context { 65 return context.WithValue(ctx, contextKeyDeterministicSignature, value) 66 } 67 68 func IsDeterministic(ctx context.Context) bool { 69 value, ok := ctx.Value(contextKeyDeterministicSignature).(bool) 70 if !ok { 71 return false 72 } 73 return value 74 }