Skip to content

Commit b44e19a

Browse files
committed
fix: issue with sha256 and prod build #1120
1 parent 2a9ec6a commit b44e19a

File tree

12 files changed

+227
-38
lines changed

12 files changed

+227
-38
lines changed

Diff for: docs/classes/HashHandler.html

+31-7
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ <h3 id="methods">
134134

135135
<tr>
136136
<td class="col-md-4">
137-
<div class="io-line">Defined in <a href="" data-line="11"
138-
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:11</a></div>
137+
<div class="io-line">Defined in <a href="" data-line="12"
138+
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:12</a></div>
139139
</td>
140140
</tr>
141141

@@ -207,28 +207,52 @@ <h3 id="methods">
207207
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { Injectable } from &#x27;@angular/core&#x27;;
208208

209209
import { factory } from &#x27;./js-sha256&#x27;;
210-
211210
const sha256 &#x3D; factory();
212211

212+
import fsha256 from &#x27;fast-sha256&#x27;;
213+
213214
/**
214215
* Abstraction for crypto algorithms
215216
*/
216217
export abstract class HashHandler {
217218
abstract calcHash(valueToHash: string, algorithm: string): Promise&lt;string&gt;;
218219
}
219220

221+
function decodeUTF8(s) {
222+
if (typeof s !&#x3D;&#x3D; &#x27;string&#x27;) throw new TypeError(&#x27;expected string&#x27;);
223+
var i,
224+
d &#x3D; s,
225+
b &#x3D; new Uint8Array(d.length);
226+
for (i &#x3D; 0; i &lt; d.length; i++) b[i] &#x3D; d.charCodeAt(i);
227+
return b;
228+
}
229+
230+
function encodeUTF8(arr) {
231+
var i,
232+
s &#x3D; [];
233+
for (i &#x3D; 0; i &lt; arr.length; i++) s.push(String.fromCharCode(arr[i]));
234+
return s.join(&#x27;&#x27;);
235+
}
236+
220237
@Injectable()
221238
export class DefaultHashHandler implements HashHandler {
222239
async calcHash(valueToHash: string, algorithm: string): Promise&lt;string&gt; {
223240
// const encoder &#x3D; new TextEncoder();
224241
// const hashArray &#x3D; await window.crypto.subtle.digest(algorithm, data);
225242
// const data &#x3D; encoder.encode(valueToHash);
226243

227-
const hashArray &#x3D; (sha256 as any).array(valueToHash);
228-
// const hashString &#x3D; this.toHashString(hashArray);
229-
const hashString &#x3D; this.toHashString2(hashArray);
244+
// const fhash &#x3D; fsha256(valueToHash);
245+
246+
const candHash &#x3D; encodeUTF8(fsha256(decodeUTF8(valueToHash)));
247+
248+
// const hashArray &#x3D; (sha256 as any).array(valueToHash);
249+
// // const hashString &#x3D; this.toHashString(hashArray);
250+
// const hashString &#x3D; this.toHashString2(hashArray);
251+
252+
// console.debug(&#x27;hash orig - cand&#x27;, candHash, hashString);
253+
// alert(1);
230254

231-
return hashString;
255+
return candHash;
232256
}
233257

234258
toHashString2(byteArray: number[]) {

Diff for: docs/dependencies.html

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
<b>base64-js</b> : ^1.5.1</li>
7979
<li>
8080
<b>bootstrap</b> : ^3.4.1</li>
81+
<li>
82+
<b>fast-sha256</b> : ^1.3.0</li>
8183
<li>
8284
<b>jsrsasign</b> : ^10.3.0</li>
8385
<li>

Diff for: docs/injectables/DefaultHashHandler.html

+35-11
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ <h3 id="methods">
127127

128128
<tr>
129129
<td class="col-md-4">
130-
<div class="io-line">Defined in <a href="" data-line="16"
131-
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:16</a></div>
130+
<div class="io-line">Defined in <a href="" data-line="33"
131+
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:33</a></div>
132132
</td>
133133
</tr>
134134

@@ -207,8 +207,8 @@ <h3 id="methods">
207207

208208
<tr>
209209
<td class="col-md-4">
210-
<div class="io-line">Defined in <a href="" data-line="36"
211-
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:36</a></div>
210+
<div class="io-line">Defined in <a href="" data-line="60"
211+
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:60</a></div>
212212
</td>
213213
</tr>
214214

@@ -275,8 +275,8 @@ <h3 id="methods">
275275

276276
<tr>
277277
<td class="col-md-4">
278-
<div class="io-line">Defined in <a href="" data-line="28"
279-
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:28</a></div>
278+
<div class="io-line">Defined in <a href="" data-line="52"
279+
class="link-to-prism">projects/lib/src/token-validation/hash-handler.ts:52</a></div>
280280
</td>
281281
</tr>
282282

@@ -332,28 +332,52 @@ <h3 id="methods">
332332
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { Injectable } from &#x27;@angular/core&#x27;;
333333

334334
import { factory } from &#x27;./js-sha256&#x27;;
335-
336335
const sha256 &#x3D; factory();
337336

337+
import fsha256 from &#x27;fast-sha256&#x27;;
338+
338339
/**
339340
* Abstraction for crypto algorithms
340341
*/
341342
export abstract class HashHandler {
342343
abstract calcHash(valueToHash: string, algorithm: string): Promise&lt;string&gt;;
343344
}
344345

346+
function decodeUTF8(s) {
347+
if (typeof s !&#x3D;&#x3D; &#x27;string&#x27;) throw new TypeError(&#x27;expected string&#x27;);
348+
var i,
349+
d &#x3D; s,
350+
b &#x3D; new Uint8Array(d.length);
351+
for (i &#x3D; 0; i &lt; d.length; i++) b[i] &#x3D; d.charCodeAt(i);
352+
return b;
353+
}
354+
355+
function encodeUTF8(arr) {
356+
var i,
357+
s &#x3D; [];
358+
for (i &#x3D; 0; i &lt; arr.length; i++) s.push(String.fromCharCode(arr[i]));
359+
return s.join(&#x27;&#x27;);
360+
}
361+
345362
@Injectable()
346363
export class DefaultHashHandler implements HashHandler {
347364
async calcHash(valueToHash: string, algorithm: string): Promise&lt;string&gt; {
348365
// const encoder &#x3D; new TextEncoder();
349366
// const hashArray &#x3D; await window.crypto.subtle.digest(algorithm, data);
350367
// const data &#x3D; encoder.encode(valueToHash);
351368

352-
const hashArray &#x3D; (sha256 as any).array(valueToHash);
353-
// const hashString &#x3D; this.toHashString(hashArray);
354-
const hashString &#x3D; this.toHashString2(hashArray);
369+
// const fhash &#x3D; fsha256(valueToHash);
370+
371+
const candHash &#x3D; encodeUTF8(fsha256(decodeUTF8(valueToHash)));
372+
373+
// const hashArray &#x3D; (sha256 as any).array(valueToHash);
374+
// // const hashString &#x3D; this.toHashString(hashArray);
375+
// const hashString &#x3D; this.toHashString2(hashArray);
376+
377+
// console.debug(&#x27;hash orig - cand&#x27;, candHash, hashString);
378+
// alert(1);
355379

356-
return hashString;
380+
return candHash;
357381
}
358382

359383
toHashString2(byteArray: number[]) {

Diff for: docs/js/search/search_index.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: docs/miscellaneous/functions.html

+110
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ <h3 id="index">Index</h3>
7070
<li>
7171
<a href="#createDefaultStorage" title="projects/lib/src/factories.ts" ><b>createDefaultStorage</b>&nbsp;&nbsp;&nbsp;(projects/.../factories.ts)</a>
7272
</li>
73+
<li>
74+
<a href="#decodeUTF8" title="projects/lib/src/token-validation/hash-handler.ts" ><b>decodeUTF8</b>&nbsp;&nbsp;&nbsp;(projects/.../hash-handler.ts)</a>
75+
</li>
76+
<li>
77+
<a href="#encodeUTF8" title="projects/lib/src/token-validation/hash-handler.ts" ><b>encodeUTF8</b>&nbsp;&nbsp;&nbsp;(projects/.../hash-handler.ts)</a>
78+
</li>
7379
</ul>
7480
</td>
7581
</tr>
@@ -232,6 +238,110 @@ <h3></h3> <table class="table table-sm table-bordered">
232238

233239

234240

241+
</tbody>
242+
</table>
243+
</section> <h3>projects/lib/src/token-validation/hash-handler.ts</h3>
244+
<section>
245+
<h3></h3> <table class="table table-sm table-bordered">
246+
<tbody>
247+
<tr>
248+
<td class="col-md-4">
249+
<a name="decodeUTF8"></a>
250+
<span class="name">
251+
<span ><b>decodeUTF8</b></span>
252+
<a href="#decodeUTF8"><span class="icon ion-ios-link"></span></a>
253+
</span>
254+
</td>
255+
</tr>
256+
<tr>
257+
<td class="col-md-4">
258+
<code>decodeUTF8(s)</code>
259+
</td>
260+
</tr>
261+
262+
263+
264+
265+
<tr>
266+
<td class="col-md-4">
267+
268+
<div class="io-description">
269+
<b>Parameters :</b>
270+
<table class="params">
271+
<thead>
272+
<tr>
273+
<td>Name</td>
274+
<td>Optional</td>
275+
</tr>
276+
</thead>
277+
<tbody>
278+
<tr>
279+
<td>s</td>
280+
281+
<td>
282+
No
283+
</td>
284+
285+
286+
</tr>
287+
</tbody>
288+
</table>
289+
</div>
290+
<div>
291+
</div>
292+
</td>
293+
</tr>
294+
</tbody>
295+
</table>
296+
<table class="table table-sm table-bordered">
297+
<tbody>
298+
<tr>
299+
<td class="col-md-4">
300+
<a name="encodeUTF8"></a>
301+
<span class="name">
302+
<span ><b>encodeUTF8</b></span>
303+
<a href="#encodeUTF8"><span class="icon ion-ios-link"></span></a>
304+
</span>
305+
</td>
306+
</tr>
307+
<tr>
308+
<td class="col-md-4">
309+
<code>encodeUTF8(arr)</code>
310+
</td>
311+
</tr>
312+
313+
314+
315+
316+
<tr>
317+
<td class="col-md-4">
318+
319+
<div class="io-description">
320+
<b>Parameters :</b>
321+
<table class="params">
322+
<thead>
323+
<tr>
324+
<td>Name</td>
325+
<td>Optional</td>
326+
</tr>
327+
</thead>
328+
<tbody>
329+
<tr>
330+
<td>arr</td>
331+
332+
<td>
333+
No
334+
</td>
335+
336+
337+
</tr>
338+
</tbody>
339+
</table>
340+
</div>
341+
<div>
342+
</div>
343+
</td>
344+
</tr>
235345
</tbody>
236346
</table>
237347
</section>

Diff for: package-lock.json

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"angular-oauth2-oidc-jwks": "^9.0.0",
4242
"base64-js": "^1.5.1",
4343
"bootstrap": "^3.4.1",
44+
"fast-sha256": "^1.3.0",
4445
"jsrsasign": "^10.3.0",
4546
"ngx-semantic-version": "^2.3.0",
4647
"rxjs": "^6.5.3",

Diff for: projects/lib/ng-package.prod.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"entryFile": "src/public_api.ts"
66
},
77
"allowedNonPeerDependencies": [
8-
"js-sha256"
8+
"js-sha256", "fast-sha256"
99
]
1010
}

Diff for: projects/lib/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"author": {
55
"name": "Manfred Steyer"
66
},
7-
"version": "12.0.2-issue.1120",
7+
"version": "12.0.2-issue.1120.2",
88
"repository": "manfredsteyer/angular-oauth2-oidc",
99
"peerDependencies": {
1010
"@angular/common": ">=12.0.0",
1111
"@angular/core": ">=12.0.0"
1212
},
1313
"dependencies": {
14-
"tslib": "^2.0.0"
14+
"tslib": "^2.0.0",
15+
"fast-sha256": "^1.3.0"
1516
}
1617
}

0 commit comments

Comments
 (0)