@@ -6,6 +6,9 @@ import { fetchAssetMetadata, getHexFromDigest } from "./github-asset";
66import { getVerifiedManifest } from "./manifest" ;
77import { getGitHubManifestUrl } from "./url" ;
88
9+ class DigestVerificationError extends Error { }
10+ class UnsupportedAlgorithmError extends Error { }
11+
912interface AlgorithmConfig {
1013 readonly manifestFile : string ;
1114}
@@ -32,7 +35,7 @@ function getManifest(algoName: string): string {
3235 return supportedAlgorithms [ algoName ] . manifestFile ;
3336 }
3437
35- throw new Error ( `Unsupported algorithm: ${ algoName } ` ) ;
38+ throw new UnsupportedAlgorithmError ( `Unsupported algorithm: ${ algoName } ` ) ;
3639}
3740
3841/**
@@ -91,7 +94,9 @@ export async function verifyAsset(
9194 const updatedAt = new Date ( metadata . updated_at ) ;
9295 if ( Number . isNaN ( updatedAt . getTime ( ) ) ) {
9396 silentUnlink ( zipPath ) ;
94- throw new Error ( `Invalid updated_at for asset ${ assetName } ` ) ;
97+ throw new DigestVerificationError (
98+ `Invalid updated_at for asset ${ assetName } ` ,
99+ ) ;
95100 }
96101
97102 /**
@@ -105,20 +110,20 @@ export async function verifyAsset(
105110 const githubHash = getHexFromDigest ( metadata . digest ) ;
106111 if ( githubHash !== actualHash ) {
107112 silentUnlink ( zipPath ) ;
108- throw new Error (
113+ throw new DigestVerificationError (
109114 `Security Mismatch: GitHub API digest (${ githubHash } ) differs from local hash (${ actualHash } )!` ,
110115 ) ;
111116 }
112117 digest_matched = true ;
113118 info ( `GitHub API digest matched! (${ metadata . digest } )` ) ;
114119 } else {
115120 warning (
116- `GitHub digest missing for asset updated on ${ metadata . updated_at . toISOString ( ) } ` ,
121+ `GitHub digest missing for asset updated on ${ updatedAt . toISOString ( ) } ` ,
117122 ) ;
118123 }
119124 }
120125 } catch ( err ) {
121- if ( err instanceof Error && err . message . startsWith ( "Security Mismatch:" ) ) {
126+ if ( err instanceof DigestVerificationError ) {
122127 throw err ; // always propagate real mismatches
123128 }
124129 warning ( `Skipping GitHub API digest check for: ${ downloadUrl } ` ) ;
0 commit comments