Class: ChecksumUtils

ChecksumUtils

mmir.tools.ChecksumUtils

A Utility class for creating / reading checksum (files).

Requires

  • module:CryptoJS

Methods

createContent(originalText, additionalInfo){String}

Creates the content for a checksum file, containing information about the size and hash-value for the supplied String argument. The result can be "written as is" to a file.
Name Type Description
originalText String the "raw" text for which to generate the checksum information
additionalInfo String optional OPTIONAL additional information to include in the checksum information (must not contain whitespaces)
Returns:
Type Description
String the checksum information as a String (formatted as content of a checksum file)

getConentSeparator(){String}

The Char used for separating fields within checksum files.
Returns:
Type Description
String the separator char (TAB)
Returns the file extension for checksum-files. CONST
Returns:
Type Description
String the default file extension for checksum files (including the separating dot, eg. ".checksum.txt")

init(cryptoImpl)

Must be called before using checksum-generation: sets/initializes the object/function for checksum generation. After first call, following calls to this function will have no effect.
Name Type Description
cryptoImpl CryptoJS optional OPTIONAL if omitted, the (global!) variable CryptoJS is used by default. This argument should be the CryptoJS object containing the MD5 function/algorithm, i.e. CryptoJS.MD5() must be a function!

isSame(rawTextContent, referenceHash, additionalInfo){Boolean}

Check if the length / checksum for a raw text is the same as the checksum-information. NOTE: The actual checksum for the raw text is only generated & checked, if the size is equal.
Name Type Description
rawTextContent String the (raw) text/content which should be checked
referenceHash String | PlainObject the checksum information to check against: either the raw content (String) of a checksum file, or the parsed contents of a checksum file, which is a PlainObject with properties: { size: INTEGER, hash: STRING, info?: STRING }
additionalInfo String optional OPTIONAL if referenceHash is a PlainObject with info property and additionalInfo must match the info property, otherwise the verification return FALSE
Returns:
Type Description
Boolean true if the raw content matches the hash

parseContent(rawTextContent){PlainObject}

Parses the raw text-content of a checksum file and returns an object with properties: { size: INTEGER, hash: STRING }
Name Type Description
rawTextContent String the raw conent of a checksum file
Returns:
Type Description
PlainObject an object with the extracted properties from the checksum-data: { size: INTEGER, hash: STRING, info?: STRING }