public Map < ChecksumType , String > calculateJavaScriptHashes ( byte [ ] byteArray ) throws WssHashException { Map < ChecksumType , String > checksums = new EnumMap <> ( ChecksumType . class ) ; try { String fileContent = IOUtils . toString ( byteArray , UTF_8 ) ; ParseResult parseResult = new JavaScriptParser ( ) . parse ( fileContent ) ; if ( parseResult != null ) { // no comments String contentWithoutComments = parseResult . getContentWithoutComments ( ) ; if ( StringUtils . isNotBlank ( contentWithoutComments ) ) { HashCalculationResult noCommentsSha1 = calculateSuperHash ( contentWithoutComments . getBytes ( ) ) ; if ( noCommentsSha1 != null ) { checksums . put ( ChecksumType . SHA1_NO_COMMENTS_SUPER_HASH , noCommentsSha1 . getFullHash ( ) ) ; } } // no headers String headerlessContent = parseResult . getContentWithoutHeaderComments ( ) ; if ( StringUtils . isNotBlank ( headerlessContent ) ) { String headerlessChecksum = calculateByteArrayHash ( headerlessContent . getBytes ( ) , HashAlgorithm . SHA1 ) ; checksums . put ( ChecksumType . SHA1_NO_HEADER , headerlessChecksum ) ; } } } catch ( Exception e ) { throw new WssHashException ( "Error calculating JavaScript hash: " + e . getMessage ( ) ) ; } return checksums ; }
Removes all JavaScript header comments from the file and calculates SHA - 1 checksum .