internal enum LibteecError : uint
{
None = 0,
+ Generic = 0xFFFF0000,
NotImplemented = 0xFFFF0009,
+ NotSupported = 0xFFFF000A,
CommunicationFailed = 0xFFFF000E,
};
case (uint)LibteecError.None:
return ;
case (uint)LibteecError.NotImplemented:
+ case (uint)LibteecError.NotSupported:
throw new NotSupportedException(string.Format("[{0}] {1} error=0x{2}",
LogTag, msg, err.ToString("X")));
case (uint)LibteecError.CommunicationFailed:
+ case (uint)LibteecError.Generic:
throw new Exception(string.Format("[{0}] {1} error=0x{2}",
LogTag, msg, err.ToString("X")));
default:
<ItemGroup>
<ProjectReference Include="..\Tizen\Tizen.csproj" />
<ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj" />
+ <ProjectReference Include="..\Tizen.System.Information\Tizen.System.Information.csproj" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
};
+ static internal class TeeFeature
+ {
+ private static string name = "http://tizen.org/feature/security.tee";
+ public static bool IsEnabled() {
+ /* FIXME - System.Information does not provide a Try-less variant of GetValue */
+ if (!Tizen.System.Information.TryGetValue(name, out bool enabled)) {
+ unchecked {
+ Interop.CheckNThrowException((int)Interop.LibteecError.Generic, "Failed to query for TEE feature");
+ }
+ }
+ return enabled;
+ }
+ }
+
/// <summary>
/// This type denotes a TEE Context, the main logical container linking a Client Application with a particular TEE.
/// </summary>
/// <exception cref="InvalidOperationException">The operation is invalid.</exception>
public Context(string name)
{
+ if (!TeeFeature.IsEnabled())
+ unchecked {
+ Interop.CheckNThrowException((int)Interop.LibteecError.NotSupported, string.Format("InitializeContext('{0}')", name));
+ }
+
context_imp = Marshal.AllocHGlobal(Marshal.SizeOf<Interop.TEEC_Context>());
if (name != null && name.Length == 0)
name = null;
try {
int ret = Interop.Libteec.InitializeContext(name, context_imp);
- Interop.CheckNThrowException(ret, string.Format("InititalizeContext('{0}')", name));
+ Interop.CheckNThrowException(ret, string.Format("InitializeContext('{0}')", name));
initialized = true;
}
catch (global::System.DllNotFoundException e)