1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | // ============================================================ |
5 | // |
6 | // AssemblyIdentity.hpp |
7 | // |
8 | |
9 | |
10 | // |
11 | // Defines the AssemblyIdentity class |
12 | // |
13 | // ============================================================ |
14 | |
15 | #ifndef __BINDER__ASSEMBLY_IDENTITY_HPP__ |
16 | #define __BINDER__ASSEMBLY_IDENTITY_HPP__ |
17 | |
18 | #include "bindertypes.hpp" |
19 | #include "assemblyversion.hpp" |
20 | |
21 | namespace BINDER_SPACE |
22 | { |
23 | class AssemblyIdentity |
24 | { |
25 | public: |
26 | enum |
27 | { |
28 | IDENTITY_FLAG_EMPTY = 0x000, |
29 | IDENTITY_FLAG_SIMPLE_NAME = 0x001, |
30 | IDENTITY_FLAG_VERSION = 0x002, |
31 | IDENTITY_FLAG_PUBLIC_KEY_TOKEN = 0x004, |
32 | IDENTITY_FLAG_PUBLIC_KEY = 0x008, |
33 | IDENTITY_FLAG_CULTURE = 0x010, |
34 | IDENTITY_FLAG_LANGUAGE = 0x020, |
35 | IDENTITY_FLAG_PROCESSOR_ARCHITECTURE = 0x040, |
36 | IDENTITY_FLAG_RETARGETABLE = 0x080, |
37 | IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL = 0x100, |
38 | IDENTITY_FLAG_CUSTOM = 0x200, |
39 | IDENTITY_FLAG_CUSTOM_NULL = 0x400, |
40 | IDENTITY_FLAG_CONTENT_TYPE = 0x800, |
41 | IDENTITY_FLAG_FULL_NAME = (IDENTITY_FLAG_SIMPLE_NAME | |
42 | IDENTITY_FLAG_VERSION) |
43 | } IdentityFlags; |
44 | |
45 | AssemblyIdentity() |
46 | { |
47 | m_dwIdentityFlags = IDENTITY_FLAG_EMPTY; |
48 | m_kProcessorArchitecture = peNone; |
49 | m_kContentType = AssemblyContentType_Default; |
50 | |
51 | // Need to pre-populate SBuffers because of bogus asserts |
52 | static const BYTE byteArr[] = { 0 }; |
53 | m_publicKeyOrTokenBLOB.SetImmutable(byteArr, sizeof(byteArr)); |
54 | m_customBLOB.SetImmutable(byteArr, sizeof(byteArr)); |
55 | } |
56 | ~AssemblyIdentity() |
57 | { |
58 | // Nothing to do here |
59 | } |
60 | |
61 | static BOOL Have(DWORD dwUseIdentityFlags, DWORD dwIdentityFlags) |
62 | { |
63 | return ((dwUseIdentityFlags & dwIdentityFlags) != 0); |
64 | } |
65 | |
66 | BOOL Have(DWORD dwIdentityFlags) |
67 | { |
68 | return Have(m_dwIdentityFlags, dwIdentityFlags); |
69 | } |
70 | |
71 | void SetHave(DWORD dwIdentityFlags) |
72 | { |
73 | m_dwIdentityFlags |= dwIdentityFlags; |
74 | } |
75 | |
76 | void SetClear(DWORD dwIdentityFlags) |
77 | { |
78 | m_dwIdentityFlags &= ~dwIdentityFlags; |
79 | } |
80 | |
81 | void CloneInto(AssemblyIdentity *pAssemblyIdentity) |
82 | { |
83 | pAssemblyIdentity->m_simpleName.Set(m_simpleName); |
84 | pAssemblyIdentity->m_simpleName.Normalize(); |
85 | pAssemblyIdentity->m_version.SetVersion(&m_version); |
86 | pAssemblyIdentity->m_cultureOrLanguage.Set(m_cultureOrLanguage); |
87 | pAssemblyIdentity->m_cultureOrLanguage.Normalize(); |
88 | pAssemblyIdentity->m_publicKeyOrTokenBLOB.Set(m_publicKeyOrTokenBLOB); |
89 | pAssemblyIdentity->m_kProcessorArchitecture = m_kProcessorArchitecture; |
90 | pAssemblyIdentity->m_kContentType = m_kContentType; |
91 | pAssemblyIdentity->m_customBLOB.Set(m_customBLOB); |
92 | pAssemblyIdentity->m_dwIdentityFlags = m_dwIdentityFlags; |
93 | } |
94 | |
95 | SString m_simpleName; |
96 | AssemblyVersion m_version; |
97 | SString m_cultureOrLanguage; |
98 | SBuffer m_publicKeyOrTokenBLOB; |
99 | PEKIND m_kProcessorArchitecture; |
100 | AssemblyContentType m_kContentType; |
101 | SBuffer m_customBLOB; |
102 | DWORD m_dwIdentityFlags; |
103 | }; |
104 | |
105 | class AssemblyIdentityUTF8 : public AssemblyIdentity |
106 | { |
107 | public: |
108 | AssemblyIdentityUTF8() |
109 | { |
110 | m_szSimpleNameUTF8 = NULL; |
111 | m_szCultureOrLanguageUTF8 = NULL; |
112 | } |
113 | |
114 | void PopulateUTF8Fields() |
115 | { |
116 | m_szSimpleNameUTF8 = m_simpleName.GetUTF8(sSimpleNameBuffer); |
117 | |
118 | if (Have(IDENTITY_FLAG_CULTURE) && !m_cultureOrLanguage.IsEmpty()) |
119 | { |
120 | m_szCultureOrLanguageUTF8 = m_cultureOrLanguage.GetUTF8(sCultureBuffer); |
121 | } |
122 | } |
123 | |
124 | inline LPCSTR GetSimpleNameUTF8() |
125 | { |
126 | return m_szSimpleNameUTF8; |
127 | } |
128 | |
129 | inline LPCSTR GetCultureOrLanguageUTF8() |
130 | { |
131 | return m_szCultureOrLanguageUTF8; |
132 | } |
133 | |
134 | inline const BYTE *GetPublicKeyOrTokenArray() |
135 | { |
136 | const BYTE *pPublicKeyOrToken = m_publicKeyOrTokenBLOB; |
137 | |
138 | return pPublicKeyOrToken; |
139 | } |
140 | |
141 | protected: |
142 | StackScratchBuffer sSimpleNameBuffer; |
143 | StackScratchBuffer sCultureBuffer; |
144 | LPCSTR m_szSimpleNameUTF8; |
145 | LPCSTR m_szCultureOrLanguageUTF8; |
146 | }; |
147 | }; |
148 | |
149 | #endif |
150 | |