/// <summary> /// Check if this TPM implements the given algorithm. /// The method sends the GetCapability command the first time it is called, /// and reuses its results during subsequent invocations. /// </summary> /// <param name="commandCode">Algorithm ID to check.</param> /// <returns>true if the given algorithm is supported by this TPM instance.</returns> public bool IsImplemented(TpmAlgId algId) { if (ImplementedAlgs == null || ImplementedAlgs.Length == 0) { ICapabilitiesUnion caps; Tpm.GetCapability(Cap.Algs, (uint)TpmAlgId.First, (uint)TpmAlgId.Last, out caps); ImplementedAlgs = Globs.ConvertAll((caps as AlgPropertyArray).algProperties, algProp => algProp.alg) .ToArray(); Debug.Assert(ImplementedAlgs.Length != 0); } return(ImplementedAlgs.Contains(algId)); }
/// <summary> /// Check if this TPM implements the given command. /// The method sends the GetCapability command the first time it is called, /// and reuses its results during subsequent invocations. /// </summary> /// <param name="commandCode">The command code to check.</param> /// <returns>true if the given command is supported by this TPM instance.</returns> public bool IsImplemented(TpmCc commandCode) { if (ImplementedCommands == null || ImplementedCommands.Length == 0) { ICapabilitiesUnion caps; uint totalCommands = Tpm2.GetProperty(Tpm, Pt.TotalCommands); Tpm.GetCapability(Cap.Commands, (uint)TpmCc.First, totalCommands, out caps); ImplementedCommands = Globs.ConvertAll((caps as CcaArray).commandAttributes, cmdAttr => (TpmCc)(cmdAttr & CcAttr.commandIndexBitMask)) .ToArray(); Debug.Assert(ImplementedCommands.Length != 0); } return(ImplementedCommands.Contains(commandCode)); }