bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorContext context, String& errorDetails) { Dictionary rawHash; if (!raw.get("hash", rawHash)) { errorDetails = context.toString("hash", "Missing or not a dictionary"); return false; } context.add("hash"); return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); }
bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryptoAlgorithm& algorithm, ErrorContext context, String& errorDetails) { context.add("Algorithm"); if (!raw.isObject()) { errorDetails = context.toString("Not an object"); return false; } String algorithmName; if (!raw.get("name", algorithmName)) { errorDetails = context.toString("name", "Missing or not a string"); return false; } const AlgorithmInfo* info = AlgorithmRegistry::instance().lookupAlgorithmByName(algorithmName); if (!info) { errorDetails = context.toString("Unrecognized algorithm name"); return false; } context.add(info->algorithmName); if (info->paramsForOperation[op] == UnsupportedOp) { errorDetails = context.toString("Unsupported operation"); return false; } blink::WebCryptoAlgorithmParamsType paramsType = static_cast<blink::WebCryptoAlgorithmParamsType>(info->paramsForOperation[op]); OwnPtr<blink::WebCryptoAlgorithmParams> params; if (!parseAlgorithmParams(raw, paramsType, params, context, errorDetails)) return false; algorithm = blink::WebCryptoAlgorithm(info->algorithmId, params.release()); return true; }
bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParamsType type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ErrorContext& context, String& errorDetails) { switch (type) { case blink::WebCryptoAlgorithmParamsTypeNone: return true; case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: context.add("AesCbcParams"); return parseAesCbcParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: context.add("AesKeyGenParams"); return parseAesKeyGenParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeHmacImportParams: context.add("HmacImportParams"); return parseHmacImportParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams: context.add("HmacKeyGenParams"); return parseHmacKeyGenParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams: context.add("RsaHashedKeyGenParams"); return parseRsaHashedKeyGenParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: context.add("RsaHashedImportParams"); return parseRsaHashedImportParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: context.add("RsaKeyGenParams"); return parseRsaKeyGenParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeAesCtrParams: context.add("AesCtrParams"); return parseAesCtrParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: context.add("AesGcmParams"); return parseAesGcmParams(raw, params, context, errorDetails); case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: // TODO notImplemented(); break; } ASSERT_NOT_REACHED(); return false; }