

const require_KeyManagementError = require('../error/KeyManagementError.js');
const require_humanDescription = require('./humanDescription.js');

//#region src/modules/kms/jwk/equals.ts
/**
* Checks if two JWK public keys have matching key types
* Supports EC, OKP, and RSA key types
*/
function assymetricJwkKeyTypeMatches(first, second) {
	if (first.kty !== second.kty) return false;
	if (first.kty === "EC" && second.kty === "EC") return first.crv === second.crv;
	if (first.kty === "OKP" && second.kty === "OKP") return first.crv === second.crv;
	if (first.kty === "RSA" && second.kty === "RSA") return true;
	return false;
}
/**
* Checks if two JWK public keys have matching key types
* Supports EC, OKP, and RSA key types
*/
function assertAsymmetricJwkKeyTypeMatches(first, second) {
	if (!assymetricJwkKeyTypeMatches(first, second)) throw new require_KeyManagementError.KeyManagementError(`Expected jwk types to match, but found ${require_humanDescription.getJwkHumanDescription(first)} and ${require_humanDescription.getJwkHumanDescription(second)}`);
}
/**
* Checks if two JWK public keys have matching key material
* Supports EC, OKP, and RSA key types
*/
function assymetricPublicJwkMatches(first, second) {
	if (!assymetricJwkKeyTypeMatches(first, second)) return false;
	if (first.kty === "EC" && second.kty === "EC") return first.x === second.x && first.y === second.y;
	if (first.kty === "OKP" && second.kty === "OKP") return first.x === second.x;
	if (first.kty === "RSA" && second.kty === "RSA") return first.n === second.n && first.e === second.e;
	return false;
}

//#endregion
exports.assertAsymmetricJwkKeyTypeMatches = assertAsymmetricJwkKeyTypeMatches;
exports.assymetricJwkKeyTypeMatches = assymetricJwkKeyTypeMatches;
exports.assymetricPublicJwkMatches = assymetricPublicJwkMatches;