Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/utils/validation-utils.js
Show All 15 Lines | import { | ||||
assertWithValidator, | assertWithValidator, | ||||
tID, | tID, | ||||
} from 'lib/utils/validation-utils.js'; | } from 'lib/utils/validation-utils.js'; | ||||
import { fetchNotAcknowledgedPolicies } from '../fetchers/policy-acknowledgment-fetchers.js'; | import { fetchNotAcknowledgedPolicies } from '../fetchers/policy-acknowledgment-fetchers.js'; | ||||
import { verifyClientSupported } from '../session/version.js'; | import { verifyClientSupported } from '../session/version.js'; | ||||
import type { Viewer } from '../session/viewer.js'; | import type { Viewer } from '../session/viewer.js'; | ||||
const convertToNewIDSchema = false; | |||||
const keyserverPrefixID = '256'; | |||||
async function validateInput<T>( | async function validateInput<T>( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
inputValidator: ?TType<T>, | inputValidator: TType<T>, | ||||
input: T, | input: mixed, | ||||
) { | ): Promise<T> { | ||||
if (!viewer.isSocket) { | if (!viewer.isSocket) { | ||||
await checkClientSupported(viewer, inputValidator, input); | await checkClientSupported(viewer, inputValidator, input); | ||||
} | } | ||||
checkInputValidator(inputValidator, input); | const convertedInput = checkInputValidator(inputValidator, input); | ||||
if ( | |||||
hasMinCodeVersion(viewer.platformDetails, 1000) && | |||||
!isWebPlatform(viewer.platformDetails?.platform) && | |||||
convertToNewIDSchema | |||||
) { | |||||
return convertClientIDsToServerIDs( | |||||
keyserverPrefixID, | |||||
inputValidator, | |||||
convertedInput, | |||||
); | |||||
} | } | ||||
const convertToNewIDSchema = false; | return convertedInput; | ||||
const keyserverPrefixID = '256'; | } | ||||
function validateOutput<T>( | function validateOutput<T>( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
outputValidator: TType<T>, | outputValidator: TType<T>, | ||||
data: T, | data: T, | ||||
): T { | ): T { | ||||
if (!outputValidator.is(data)) { | if (!outputValidator.is(data)) { | ||||
console.trace( | console.trace( | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | const conversionFunction = id => { | ||||
} | } | ||||
throw new ServerError('invalid_client_id_prefix'); | throw new ServerError('invalid_client_id_prefix'); | ||||
}; | }; | ||||
return convertObject(outputValidator, data, [tID], conversionFunction); | return convertObject(outputValidator, data, [tID], conversionFunction); | ||||
} | } | ||||
function checkInputValidator<T>(inputValidator: ?TType<T>, input: T) { | function checkInputValidator<T>(inputValidator: TType<T>, input: mixed): T { | ||||
if (!inputValidator || inputValidator.is(input)) { | if (inputValidator.is(input)) { | ||||
return; | return assertWithValidator(input, inputValidator); | ||||
} | } | ||||
const error = new ServerError('invalid_parameters'); | const error = new ServerError('invalid_parameters'); | ||||
error.sanitizedInput = input ? sanitizeInput(inputValidator, input) : null; | error.sanitizedInput = input ? sanitizeInput(inputValidator, input) : null; | ||||
throw error; | throw error; | ||||
} | } | ||||
async function checkClientSupported<T>( | async function checkClientSupported<T>( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
▲ Show 20 Lines • Show All 220 Lines • Show Last 20 Lines |