11import type { MessageDigest , SHA1State } from './types'
2- import { ByteStringBuffer } from 'ts-security-utils'
2+ import type { ByteStringBuffer } from 'ts-security-utils'
3+ import { createBuffer } from 'ts-security-utils'
34
45/**
56 * SHA-1 implementation
@@ -42,10 +43,10 @@ export const sha1 = {
4243 let state : SHA1State = { ..._initialState }
4344
4445 // Input buffer
45- let _input = new ByteStringBuffer ( )
46+ let _input = createBuffer ( )
4647
4748 // Used for word operations
48- const _w = Array . from ( { length : 80 } )
49+ const _w : number [ ] = new Array ( 80 ) . fill ( 0 )
4950
5051 // Message digest object
5152 const md : MessageDigest = {
@@ -61,7 +62,7 @@ export const sha1 = {
6162 */
6263 start ( ) {
6364 state = { ..._initialState }
64- _input = new ByteStringBuffer ( )
65+ _input = createBuffer ( )
6566 this . messageLength = 0
6667 this . fullMessageLength = [ 0 , 0 ]
6768 return this
@@ -75,10 +76,10 @@ export const sha1 = {
7576 update ( msg : string | ByteStringBuffer , encoding = 'raw' ) {
7677 if ( typeof msg === 'string' ) {
7778 if ( encoding === 'utf8' ) {
78- msg = new ByteStringBuffer ( ) . putString ( msg )
79+ msg = createBuffer ( ) . putString ( msg )
7980 }
8081 else {
81- msg = new ByteStringBuffer ( ) . putBytes ( msg )
82+ msg = createBuffer ( ) . putBytes ( msg )
8283 }
8384 }
8485
@@ -119,7 +120,7 @@ export const sha1 = {
119120 _finalizeHash ( finalInput , finalState , finalMessageLength )
120121
121122 // Create digest from state
122- const digest = new ByteStringBuffer ( )
123+ const digest = createBuffer ( )
123124 digest . putInt32 ( finalState . h0 )
124125 digest . putInt32 ( finalState . h1 )
125126 digest . putInt32 ( finalState . h2 )
0 commit comments