[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mono / metadata / security-manager.c
blobefad0ecf046a0d6aff3215a390e61aa56ebb30e2
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")
19 static MonoSecurityMode mono_security_mode = MONO_SECURITY_MODE_NONE;
21 void
22 mono_security_set_mode (MonoSecurityMode mode)
24 mono_security_mode = mode;
27 MonoSecurityMode
28 mono_security_get_mode (void)
30 return mono_security_mode;
33 #ifndef DISABLE_SECURITY
35 static MonoSecurityManager secman;
37 MonoSecurityManager*
38 mono_security_manager_get_methods (void)
40 /* Already initialized ? */
41 if (secman.securitymanager)
42 return &secman;
44 /* Initialize */
45 secman.securitymanager = mono_class_get_security_manager_class ();
46 if (!m_class_is_inited (secman.securitymanager))
47 mono_class_init_internal (secman.securitymanager);
49 return &secman;
52 #else
54 MonoSecurityManager*
55 mono_security_manager_get_methods (void)
57 return NULL;
60 #endif /* DISABLE_SECURITY */
63 * @publickey An encoded (with header) public key
64 * @size The length of the public key
66 * returns TRUE if the public key is the ECMA "key", FALSE otherwise
68 * ECMA key isn't a real public key - it's simply an empty (but valid) header
69 * so it's length (16) and value (00000000000000000400000000000000) are
70 * constants.
72 gboolean
73 mono_is_ecma_key (const char *publickey, int size)
75 int i;
76 if ((publickey == NULL) || (size != MONO_ECMA_KEY_LENGTH) || (publickey [8] != 0x04))
77 return FALSE;
79 for (i=0; i < size; i++) {
80 if ((publickey [i] != 0x00) && (i != 8))
81 return FALSE;
83 return TRUE;
86 /* System.Security icalls */
88 MonoBoolean
89 ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
91 /* SecurityManager is internal for Moonlight and SecurityEnabled is used to know if CoreCLR is active
92 * (e.g. plugin executing in the browser) or not (e.g. smcs compiling source code with corlib 2.1)
94 return (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR);
97 void
98 ves_icall_System_Security_SecurityManager_set_SecurityEnabled (MonoBoolean value)