Type UnionElementFromSelector(Type unionInterface, object selector)
{
if (unionInterface == typeof(INameUnion))
{
switch((NameUnionTagValues)selector)
{
case NameUnionTagValues.TagTpmuNameTpmtHa: return typeof(TpmHash);
case NameUnionTagValues.TagTpmuNameTpmHandle: return typeof(TpmHandle);
}
}
else if (unionInterface == typeof(ICapabilitiesUnion))
{
switch((Cap)selector)
{
case Cap.Algs: return typeof(AlgPropertyArray);
case Cap.Handles: return typeof(HandleArray);
case Cap.Commands: return typeof(CcaArray);
case Cap.PpCommands: return typeof(CcArray);
case Cap.AuditCommands: return typeof(CcArray);
case Cap.Pcrs: return typeof(PcrSelectionArray);
case Cap.TpmProperties: return typeof(TaggedTpmPropertyArray);
case Cap.PcrProperties: return typeof(TaggedPcrPropertyArray);
case Cap.EccCurves: return typeof(EccCurveArray);
}
}
else if (unionInterface == typeof(IAttestUnion))
{
switch((TpmSt)selector)
{
case TpmSt.AttestCertify: return typeof(CertifyInfo);
case TpmSt.AttestCreation: return typeof(CreationInfo);
case TpmSt.AttestQuote: return typeof(QuoteInfo);
case TpmSt.AttestCommandAudit: return typeof(CommandAuditInfo);
case TpmSt.AttestSessionAudit: return typeof(SessionAuditInfo);
case TpmSt.AttestTime: return typeof(TimeAttestInfo);
case TpmSt.AttestNv: return typeof(NvCertifyInfo);
}
}
else if (unionInterface == typeof(ISymDetailsUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Tdes: return typeof(TdesSymDetails);
case TpmAlgId.Aes: return typeof(AesSymDetails);
case TpmAlgId.Sm4: return typeof(Sm4SymDetails);
case TpmAlgId.Camellia: return typeof(CamelliaSymDetails);
case TpmAlgId.Any: return typeof(AnySymDetails);
case TpmAlgId.Xor: return typeof(XorSymDetails);
case TpmAlgId.Null: return typeof(NullSymDetails);
}
}
else if (unionInterface == typeof(ISensitiveCreateUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Any: return typeof(Byte);
case TpmAlgId.Any2: return typeof(TpmDerive);
}
}
else if (unionInterface == typeof(ISchemeKeyedhashUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Hmac: return typeof(SchemeHmac);
case TpmAlgId.Xor: return typeof(SchemeXor);
case TpmAlgId.Null: return typeof(NullSchemeKeyedhash);
}
}
else if (unionInterface == typeof(ISigSchemeUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Rsassa: return typeof(SigSchemeRsassa);
case TpmAlgId.Rsapss: return typeof(SigSchemeRsapss);
case TpmAlgId.Ecdsa: return typeof(SigSchemeEcdsa);
case TpmAlgId.Ecdaa: return typeof(SigSchemeEcdaa);
case TpmAlgId.Sm2: return typeof(SigSchemeSm2);
case TpmAlgId.Ecschnorr: return typeof(SigSchemeEcschnorr);
case TpmAlgId.Hmac: return typeof(SchemeHmac);
case TpmAlgId.Any: return typeof(SchemeHash);
case TpmAlgId.Null: return typeof(NullSigScheme);
}
}
else if (unionInterface == typeof(IKdfSchemeUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Mgf1: return typeof(SchemeMgf1);
case TpmAlgId.Kdf1Sp80056a: return typeof(SchemeKdf1Sp80056a);
case TpmAlgId.Kdf2: return typeof(SchemeKdf2);
case TpmAlgId.Kdf1Sp800108: return typeof(SchemeKdf1Sp800108);
case TpmAlgId.Null: return typeof(NullKdfScheme);
}
}
else if (unionInterface == typeof(IAsymSchemeUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Ecdh: return typeof(KeySchemeEcdh);
case TpmAlgId.Ecmqv: return typeof(KeySchemeEcmqv);
case TpmAlgId.Rsassa: return typeof(SigSchemeRsassa);
case TpmAlgId.Rsapss: return typeof(SigSchemeRsapss);
case TpmAlgId.Ecdsa: return typeof(SigSchemeEcdsa);
case TpmAlgId.Ecdaa: return typeof(SigSchemeEcdaa);
case TpmAlgId.Sm2: return typeof(SigSchemeSm2);
case TpmAlgId.Ecschnorr: return typeof(SigSchemeEcschnorr);
case TpmAlgId.Rsaes: return typeof(EncSchemeRsaes);
case TpmAlgId.Oaep: return typeof(EncSchemeOaep);
case TpmAlgId.Any: return typeof(SchemeHash);
case TpmAlgId.Null: return typeof(NullAsymScheme);
}
}
else if (unionInterface == typeof(ISignatureUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Rsassa: return typeof(SignatureRsassa);
case TpmAlgId.Rsapss: return typeof(SignatureRsapss);
case TpmAlgId.Ecdsa: return typeof(SignatureEcdsa);
case TpmAlgId.Ecdaa: return typeof(SignatureEcdaa);
case TpmAlgId.Sm2: return typeof(SignatureSm2);
case TpmAlgId.Ecschnorr: return typeof(SignatureEcschnorr);
case TpmAlgId.Hmac: return typeof(TpmHash);
case TpmAlgId.Any: return typeof(SchemeHash);
case TpmAlgId.Null: return typeof(NullSignature);
}
}
else if (unionInterface == typeof(IEncryptedSecretUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Ecc: return typeof(Byte);
case TpmAlgId.Rsa: return typeof(Byte);
case TpmAlgId.Symcipher: return typeof(Byte);
case TpmAlgId.Keyedhash: return typeof(Byte);
}
}
else if (unionInterface == typeof(IPublicIdUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Keyedhash: return typeof(Tpm2bDigestKeyedhash);
case TpmAlgId.Symcipher: return typeof(Tpm2bDigestSymcipher);
case TpmAlgId.Rsa: return typeof(Tpm2bPublicKeyRsa);
case TpmAlgId.Ecc: return typeof(EccPoint);
case TpmAlgId.Any: return typeof(TpmDerive);
}
}
else if (unionInterface == typeof(IPublicParmsUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Keyedhash: return typeof(KeyedhashParms);
case TpmAlgId.Symcipher: return typeof(SymcipherParms);
case TpmAlgId.Rsa: return typeof(RsaParms);
case TpmAlgId.Ecc: return typeof(EccParms);
case TpmAlgId.Any: return typeof(AsymParms);
}
}
else if (unionInterface == typeof(ISensitiveCompositeUnion))
{
switch((TpmAlgId)selector)
{
case TpmAlgId.Rsa: return typeof(Tpm2bPrivateKeyRsa);
case TpmAlgId.Ecc: return typeof(Tpm2bEccParameter);
case TpmAlgId.Keyedhash: return typeof(Tpm2bSensitiveData);
case TpmAlgId.Symcipher: return typeof(Tpm2bSymKey);
case TpmAlgId.Any: return typeof(Tpm2bPrivateVendorSpecific);
}
}
else
{
throw new Exception("Unknown union interface type " + unionInterface.Name);
}
throw new Exception("Unknown selector value" + selector + " for " + unionInterface.Name + " union");
}
}