src/extensions/default/AutoUpdate/node/AutoUpdateDomain.js
function validateChecksum(requester, params) {
        params = params || {
            filePath: installerPath,
            expectedChecksum: _updateParams.checksum
        };

        var hash = crypto.createHash('sha256'),
            currentRequester = requester || "";

        if (fs.existsSync(params.filePath)) {
            var stream = fs.createReadStream(params.filePath);

            stream.on('data', function (data) {
                hash.update(data);
            });

            stream.on('end', function () {
                var calculatedChecksum = hash.digest('hex'),
                    isValidChecksum = (params.expectedChecksum === calculatedChecksum),
                    status;

                if (isValidChecksum) {
                    if (process.platform === "darwin") {
                        status = {
                            valid: true,
                            installerPath: installerPath,
                            logFilePath: logFilePath,
                            installStatusFilePath: installStatusFilePath
                        };
                    } else if (process.platform === "win32") {
                        status = {
                            valid: true,
                            installerPath: quoteAndConvert(installerPath, true),
                            logFilePath: quoteAndConvert(logFilePath, true),
                            installStatusFilePath: installStatusFilePath
                        };
                    }
                } else {
                    status = {
                        valid: false,
                        err: nodeErrorMessages.CHECKSUM_DID_NOT_MATCH
                    };
                }
                postMessageToBrackets(MessageIds.NOTIFY_VALIDATION_STATUS, currentRequester, status);
            });
        } else {
            var status = {
                valid: false,
                err: nodeErrorMessages.INSTALLER_NOT_FOUND
            };
            postMessageToBrackets(MessageIds.NOTIFY_VALIDATION_STATUS, currentRequester, status);
        }
    }
function validateChecksum(requester, params) {
        params = params || {
            filePath: installerPath,
            expectedChecksum: _updateParams.checksum
        };

        var hash = crypto.createHash('sha256'),
            currentRequester = requester || "";

        if (fs.existsSync(params.filePath)) {
            var stream = fs.createReadStream(params.filePath);

            stream.on('data', function (data) {
                hash.update(data);
            });

            stream.on('end', function () {
                var calculatedChecksum = hash.digest('hex'),
                    isValidChecksum = (params.expectedChecksum === calculatedChecksum),
                    status;

                if (isValidChecksum) {
                    if (process.platform === "darwin") {
                        status = {
                            valid: true,
                            installerPath: installerPath,
                            logFilePath: logFilePath,
                            installStatusFilePath: installStatusFilePath
                        };
                    } else if (process.platform === "win32") {
                        status = {
                            valid: true,
                            installerPath: quoteAndConvert(installerPath, true),
                            logFilePath: quoteAndConvert(logFilePath, true),
                            installStatusFilePath: installStatusFilePath
                        };
                    }
                } else {
                    status = {
                        valid: false,
                        err: nodeErrorMessages.CHECKSUM_DID_NOT_MATCH
                    };
                }
                postMessageToBrackets(MessageIds.NOTIFY_VALIDATION_STATUS, currentRequester, status);
            });
        } else {
            var status = {
                valid: false,
                err: nodeErrorMessages.INSTALLER_NOT_FOUND
            };
            postMessageToBrackets(MessageIds.NOTIFY_VALIDATION_STATUS, currentRequester, status);
        }
    }
function validateChecksum ( requester , params ) { params = params || { filePath : installerPath , expectedChecksum : _updateParams . checksum } ; var hash = crypto . createHash ( 'sha256' ) , currentRequester = requester || "" ; if ( fs . existsSync ( params . filePath ) ) { var stream = fs . createReadStream ( params . filePath ) ; stream . on ( 'data' , function ( data ) { hash . update ( data ) ; } ) ; stream . on ( 'end' , function ( ) { var calculatedChecksum = hash . digest ( 'hex' ) , isValidChecksum = ( params . expectedChecksum === calculatedChecksum ) , status ; if ( isValidChecksum ) { if ( process . platform === "darwin" ) { status = { valid : true , installerPath : installerPath , logFilePath : logFilePath , installStatusFilePath : installStatusFilePath } ; } else if ( process . platform === "win32" ) { status = { valid : true , installerPath : quoteAndConvert ( installerPath , true ) , logFilePath : quoteAndConvert ( logFilePath , true ) , installStatusFilePath : installStatusFilePath } ; } } else { status = { valid : false , err : nodeErrorMessages . CHECKSUM_DID_NOT_MATCH } ; } postMessageToBrackets ( MessageIds . NOTIFY_VALIDATION_STATUS , currentRequester , status ) ; } ) ; } else { var status = { valid : false , err : nodeErrorMessages . INSTALLER_NOT_FOUND } ; postMessageToBrackets ( MessageIds . NOTIFY_VALIDATION_STATUS , currentRequester , status ) ; } }
Validates the checksum of a file against a given checksum
@param {object} params - json containing {
filePath - path to the file,
expectedChecksum - the checksum to validate against }
Validates the checksum of a file against a given checksum