@@ -31,6 +31,7 @@ import { UFC_REASON, UFC_VARIATION_TYPE } from './ufc-enums'
3131const SUPPORTED_FEATURE_LEVEL = 0
3232const compiledRegexCache = new WeakMap < FlagsConfiguration , Map < number , RegExp | null > > ( )
3333const validatedSortedArrays = new WeakSet < object > ( )
34+ const validatedSha256Arrays = new WeakSet < object > ( )
3435
3536export function evaluateProtobufConfiguration < T extends FlagValueType > (
3637 configuration : FlagsConfiguration ,
@@ -443,10 +444,19 @@ function isJsonValue(value: unknown): value is FlagValue {
443444}
444445
445446function containsBytes ( values : Uint8Array [ ] , value : Uint8Array ) : boolean {
447+ validateSha256Hashes ( values )
446448 ensureSorted ( values , compareBytes , 'SHA-256 hashes' )
447449 return containsSorted ( values , ( candidate ) => compareBytes ( candidate , value ) )
448450}
449451
452+ function validateSha256Hashes ( values : Uint8Array [ ] ) : void {
453+ if ( validatedSha256Arrays . has ( values ) ) return
454+ if ( values . some ( ( hash ) => hash . length !== 32 ) ) {
455+ throw new FlagConfigurationError ( 'SHA-256 hashes must contain 32 bytes' )
456+ }
457+ validatedSha256Arrays . add ( values )
458+ }
459+
450460function compareStrings ( left : string , right : string ) : number {
451461 return left === right ? 0 : left < right ? - 1 : 1
452462}
0 commit comments