

import { KnownJwaContentEncryptionAlgorithms } from "../jwk/jwa.mjs";
import { zKmsJwkPrivateOct } from "../jwk/kty/oct/octJwk.mjs";
import { zKmsKeyId } from "./common.mjs";
import { zKmsKeyAgreementDecryptOptions } from "./KmsKeyAgreementDecryptOptions.mjs";
import { z } from "zod";

//#region src/modules/kms/options/KmsDecryptOptions.ts
const zKmsDecryptDataDecryptionAesGcm = z.object({
	algorithm: z.enum([
		KnownJwaContentEncryptionAlgorithms.A128GCM,
		KnownJwaContentEncryptionAlgorithms.A192GCM,
		KnownJwaContentEncryptionAlgorithms.A256GCM
	]),
	iv: z.instanceof(Uint8Array).refine((iv) => iv.length === 12, "iv must be 12 bytes for AES GCM"),
	aad: z.optional(z.instanceof(Uint8Array)),
	tag: z.instanceof(Uint8Array)
});
const zKmsDecryptDataDecryptionAesCbc = z.object({
	algorithm: z.enum([KnownJwaContentEncryptionAlgorithms.A128CBC, KnownJwaContentEncryptionAlgorithms.A256CBC]),
	iv: z.instanceof(Uint8Array).refine((iv) => iv.length === 16, "iv must be 16 bytes for AES CBC")
});
const zKmsDecryptDataDecryptionAesCbcHmac = z.object({
	algorithm: z.enum([
		KnownJwaContentEncryptionAlgorithms.A128CBC_HS256,
		KnownJwaContentEncryptionAlgorithms.A192CBC_HS384,
		KnownJwaContentEncryptionAlgorithms.A256CBC_HS512
	]),
	iv: z.instanceof(Uint8Array).refine((iv) => iv.length === 16, "iv must be 16 bytes for AES CBC with HMAC"),
	aad: z.optional(z.instanceof(Uint8Array)),
	tag: z.instanceof(Uint8Array)
});
const zKmsDecryptDataDecryptionSalsa = z.object({
	algorithm: z.enum([KnownJwaContentEncryptionAlgorithms["XSALSA20-POLY1305"]]),
	iv: z.instanceof(Uint8Array).optional()
});
const zKmsDecryptDataDecryptionC20p = z.object({
	algorithm: z.enum([KnownJwaContentEncryptionAlgorithms.C20P, KnownJwaContentEncryptionAlgorithms.XC20P]),
	iv: z.instanceof(Uint8Array),
	aad: z.optional(z.instanceof(Uint8Array)),
	tag: z.instanceof(Uint8Array)
});
const zKmsDecryptDataDecryption = z.discriminatedUnion("algorithm", [
	zKmsDecryptDataDecryptionAesCbc,
	zKmsDecryptDataDecryptionAesCbcHmac,
	zKmsDecryptDataDecryptionAesGcm,
	zKmsDecryptDataDecryptionC20p,
	zKmsDecryptDataDecryptionSalsa
]);
const zKmsDecryptOptions = z.object({
	key: z.union([
		z.object({
			keyId: zKmsKeyId,
			privateJwk: z.never().optional(),
			keyAgreement: z.never().optional()
		}),
		z.object({
			privateJwk: zKmsJwkPrivateOct.describe("A private oct (symmetric) jwk"),
			keyId: z.never().optional(),
			keyAgreement: z.never().optional()
		}),
		z.object({
			keyAgreement: zKmsKeyAgreementDecryptOptions,
			keyId: z.never().optional(),
			privateJwk: z.never().optional()
		})
	]),
	decryption: zKmsDecryptDataDecryption.describe("Options related to the decryption algorithm to use for decrypting the data"),
	encrypted: z.instanceof(Uint8Array).describe("The encrypted data to decrypt")
});

//#endregion
export { zKmsDecryptOptions };
//# sourceMappingURL=KmsDecryptOptions.mjs.map