mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 23:09:34 +00:00
refactor(dotnet): share assembly key classification (#17040)
This commit is contained in:
1 parent
6f8b1d3548
commit
7b7fe6bbbe
1 file changed
+15
-23
@@ -47,19 +47,18 @@ type CustomAttribute = ManagedArtifactInspection["attributes"][number];
|
||||
|
||||
const publicKeyIdentity = (
|
||||
bytes: Buffer,
|
||||
kind: "public-key" | "public-key-token",
|
||||
flags: number,
|
||||
layout: ManagedMetadataLayout,
|
||||
): AssemblyIdentity["public_key"] => ({
|
||||
kind: bytes.length === 0 ? "none" : kind,
|
||||
byte_length: bytes.length,
|
||||
sha256:
|
||||
bytes.length === 0
|
||||
? null
|
||||
: managedDecodeBudget(layout).digest(bytes, "sha256"),
|
||||
token:
|
||||
bytes.length === 0
|
||||
? null
|
||||
: kind === "public-key"
|
||||
): AssemblyIdentity["public_key"] => {
|
||||
if (bytes.length === 0)
|
||||
return { kind: "none", byte_length: 0, sha256: null, token: null };
|
||||
const kind = (flags & 1) === 0 ? "public-key-token" : "public-key";
|
||||
return {
|
||||
kind,
|
||||
byte_length: bytes.length,
|
||||
sha256: managedDecodeBudget(layout).digest(bytes, "sha256"),
|
||||
token:
|
||||
kind === "public-key"
|
||||
? Buffer.from(managedDecodeBudget(layout).digest(bytes, "sha1"), "hex")
|
||||
.subarray(-8)
|
||||
.reverse()
|
||||
@@ -67,7 +66,8 @@ const publicKeyIdentity = (
|
||||
: bytes.length === 8
|
||||
? bytes.toString("hex")
|
||||
: null,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const readModule = (
|
||||
bytes: Buffer,
|
||||
@@ -135,11 +135,7 @@ export const readAssembly = (
|
||||
culture: culture.length === 0 ? null : culture,
|
||||
flags,
|
||||
hash_algorithm: hashAlgorithm,
|
||||
public_key: publicKeyIdentity(
|
||||
key,
|
||||
(flags & 1) === 0 ? "public-key-token" : "public-key",
|
||||
layout,
|
||||
),
|
||||
public_key: publicKeyIdentity(key, flags, layout),
|
||||
token: metadataToken(32, 1),
|
||||
row_offset: table.offset,
|
||||
};
|
||||
@@ -196,11 +192,7 @@ export const readAssemblyReference = (
|
||||
version,
|
||||
culture: culture.length === 0 ? null : culture,
|
||||
flags,
|
||||
public_key_or_token: publicKeyIdentity(
|
||||
keyOrToken,
|
||||
(flags & 1) === 0 ? "public-key-token" : "public-key",
|
||||
layout,
|
||||
),
|
||||
public_key_or_token: publicKeyIdentity(keyOrToken, flags, layout),
|
||||
hash_value_sha256:
|
||||
hashValue.length === 0
|
||||
? null
|
||||
|
||||
Reference in new issue
Block a user