(ctx context.Context, validKeys [][]byte)
| 56 | } |
| 57 | |
| 58 | func verifySource(ctx context.Context, validKeys [][]byte) error { |
| 59 | md := rpcmetadata.FromIncomingContext(ctx) |
| 60 | switch md.AuthType { |
| 61 | case AuthType: |
| 62 | case "": |
| 63 | return errNoClusterKey.New() |
| 64 | default: |
| 65 | return errUnsupportedAuthType.WithAttributes("auth_type", md.AuthType) |
| 66 | } |
| 67 | key, err := hex.DecodeString(md.AuthValue) |
| 68 | if err != nil { |
| 69 | return errInvalidClusterKey.WithCause(err) |
| 70 | } |
| 71 | for _, acceptedKey := range validKeys { |
| 72 | if subtle.ConstantTimeCompare(acceptedKey, key) == 1 { |
| 73 | return nil |
| 74 | } |
| 75 | } |
| 76 | return errInvalidClusterKey.New() |
| 77 | } |
| 78 | |
| 79 | // Authorized returns whether the context has been identified as a cluster call. |
| 80 | // It panics if it does not inherit from `NewContext`. |
no test coverage detected