X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fpeertube-crypto.ts;h=0ac87512704177f28fff94c7c90f38f6f883c4c4;hb=46757b477c1adb5f98060d15998a3852e18902a6;hp=a4e9672e61927c184a4cf1da07274aca7b1fad09;hpb=65fcc3119c334b75dd13bcfdebf186afdc580a8f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index a4e9672e6..0ac875127 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -1,7 +1,7 @@ -import crypto = require('crypto') -import bcrypt = require('bcrypt') -import fs = require('fs') -import openssl = require('openssl-wrapper') +import * as crypto from 'crypto' +import * as bcrypt from 'bcrypt' +import * as fs from 'fs' +import * as openssl from 'openssl-wrapper' import { join } from 'path' import { @@ -14,7 +14,7 @@ import { } from '../initializers' import { logger } from './logger' -function checkSignature (publicKey, data, hexSignature) { +function checkSignature (publicKey: string, data: string, hexSignature: string) { const verify = crypto.createVerify(SIGNATURE_ALGORITHM) let dataString @@ -35,10 +35,10 @@ function checkSignature (publicKey, data, hexSignature) { return isValid } -function sign (data) { +function sign (data: string|Object) { const sign = crypto.createSign(SIGNATURE_ALGORITHM) - let dataString + let dataString: string if (typeof data === 'string') { dataString = data } else { @@ -60,7 +60,7 @@ function sign (data) { return signature } -function comparePassword (plainPassword, hashPassword, callback) { +function comparePassword (plainPassword: string, hashPassword: string, callback: (err: Error, match?: boolean) => void) { bcrypt.compare(plainPassword, hashPassword, function (err, isPasswordMatch) { if (err) return callback(err) @@ -68,7 +68,7 @@ function comparePassword (plainPassword, hashPassword, callback) { }) } -function createCertsIfNotExist (callback) { +function createCertsIfNotExist (callback: (err: Error) => void) { certsExist(function (err, exist) { if (err) return callback(err) @@ -82,7 +82,7 @@ function createCertsIfNotExist (callback) { }) } -function cryptPassword (password, callback) { +function cryptPassword (password: string, callback: (err: Error, hash?: string) => void) { bcrypt.genSalt(BCRYPT_SALT_SIZE, function (err, salt) { if (err) return callback(err) @@ -92,12 +92,12 @@ function cryptPassword (password, callback) { }) } -function getMyPrivateCert (callback) { +function getMyPrivateCert (callback: (err: Error, privateCert: string) => void) { const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME) fs.readFile(certPath, 'utf8', callback) } -function getMyPublicCert (callback) { +function getMyPublicCert (callback: (err: Error, publicCert: string) => void) { const certPath = join(CONFIG.STORAGE.CERT_DIR, PUBLIC_CERT_NAME) fs.readFile(certPath, 'utf8', callback) } @@ -116,7 +116,7 @@ export { // --------------------------------------------------------------------------- -function certsExist (callback) { +function certsExist (callback: (err: Error, certsExist: boolean) => void) { const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME) fs.access(certPath, function (err) { // If there is an error the certificates do not exist @@ -125,14 +125,14 @@ function certsExist (callback) { }) } -function createCerts (callback) { +function createCerts (callback: (err: Error) => void) { certsExist(function (err, exist) { if (err) return callback(err) if (exist === true) { - const string = 'Certs already exist.' - logger.warning(string) - return callback(new Error(string)) + const errorMessage = 'Certs already exist.' + logger.warning(errorMessage) + return callback(new Error(errorMessage)) } logger.info('Generating a RSA key...')