[Mono.Runtime.Tests] Exclude simd tests
[mono-project.git] / mono / metadata / security-manager.c
bloba5f1e15d2e8db8425059a201e627b9927bb3c6ad
1 /**
2 * \file
3 * Security Manager (Unmanaged side)
5 * Author:
6 * Sebastien Pouliot <sebastien@ximian.com>
8 * Copyright 2005-2009 Novell, Inc (http://www.novell.com)
9 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
12 #include <config.h>
13 #include "security-manager.h"
14 #include "class-init.h"
16 /* Class lazy loading functions */
17 static GENERATE_GET_CLASS_WITH_CACHE (security_manager, "System.Security", "SecurityManager")
18 static GENERATE_TRY_GET_CLASS_WITH_CACHE (execution_context, "System.Threading", "ExecutionContext")
20 static MonoSecurityMode mono_security_mode = MONO_SECURITY_MODE_NONE;
22 void
23 mono_security_set_mode (MonoSecurityMode mode)
25 mono_security_mode = mode;
28 MonoSecurityMode
29 mono_security_get_mode (void)
31 return mono_security_mode;
34 #ifndef DISABLE_SECURITY
36 static MonoSecurityManager secman;
38 MonoSecurityManager*
39 mono_security_manager_get_methods (void)
41 /* Already initialized ? */
42 if (secman.securitymanager)
43 return &secman;
45 /* Initialize */
46 secman.securitymanager = mono_class_get_security_manager_class ();
47 if (!m_class_is_inited (secman.securitymanager))
48 mono_class_init_internal (secman.securitymanager);
50 return &secman;
53 #else
55 MonoSecurityManager*
56 mono_security_manager_get_methods (void)
58 return NULL;
61 #endif /* DISABLE_SECURITY */
64 * @publickey An encoded (with header) public key
65 * @size The length of the public key
67 * returns TRUE if the public key is the ECMA "key", FALSE otherwise
69 * ECMA key isn't a real public key - it's simply an empty (but valid) header
70 * so it's length (16) and value (00000000000000000400000000000000) are
71 * constants.
73 gboolean
74 mono_is_ecma_key (const char *publickey, int size)
76 int i;
77 if ((publickey == NULL) || (size != MONO_ECMA_KEY_LENGTH) || (publickey [8] != 0x04))
78 return FALSE;
80 for (i=0; i < size; i++) {
81 if ((publickey [i] != 0x00) && (i != 8))
82 return FALSE;
84 return TRUE;
88 * Context propagation is required when:
89 * (a) the security manager is active (1.x and later)
90 * (b) other contexts needs to be propagated (2.x and later)
92 * returns NULL if no context propagation is required, else the returns the
93 * MonoMethod to call to Capture the ExecutionContext.
95 MonoMethod*
96 mono_get_context_capture_method (void)
98 static MonoMethod *method = NULL;
100 if (mono_image_get_assembly (mono_defaults.corlib)->aname.major < 2)
101 return NULL;
103 /* older corlib revisions won't have the class (nor the method) */
104 MonoClass *execution_context = mono_class_try_get_execution_context_class ();
105 if (execution_context && !method) {
106 ERROR_DECL (error);
107 mono_class_init_internal (execution_context);
108 method = mono_class_get_method_from_name_checked (execution_context, "Capture", 0, 0, error);
109 mono_error_assert_ok (error);
112 return method;
116 /* System.Security icalls */
118 MonoBoolean
119 ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
121 /* SecurityManager is internal for Moonlight and SecurityEnabled is used to know if CoreCLR is active
122 * (e.g. plugin executing in the browser) or not (e.g. smcs compiling source code with corlib 2.1)
124 return (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR);
127 void
128 ves_icall_System_Security_SecurityManager_set_SecurityEnabled (MonoBoolean value)