aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/peertube-crypto.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
commit69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch)
treead199a18ec3c322460d6f9523fc383ee562554e0 /server/helpers/peertube-crypto.ts
parent4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff)
downloadPeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip
Type functions
Diffstat (limited to 'server/helpers/peertube-crypto.ts')
-rw-r--r--server/helpers/peertube-crypto.ts26
1 files changed, 13 insertions, 13 deletions
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts
index feb32a4cd..0ac875127 100644
--- a/server/helpers/peertube-crypto.ts
+++ b/server/helpers/peertube-crypto.ts
@@ -14,7 +14,7 @@ import {
14} from '../initializers' 14} from '../initializers'
15import { logger } from './logger' 15import { logger } from './logger'
16 16
17function checkSignature (publicKey, data, hexSignature) { 17function checkSignature (publicKey: string, data: string, hexSignature: string) {
18 const verify = crypto.createVerify(SIGNATURE_ALGORITHM) 18 const verify = crypto.createVerify(SIGNATURE_ALGORITHM)
19 19
20 let dataString 20 let dataString
@@ -35,10 +35,10 @@ function checkSignature (publicKey, data, hexSignature) {
35 return isValid 35 return isValid
36} 36}
37 37
38function sign (data) { 38function sign (data: string|Object) {
39 const sign = crypto.createSign(SIGNATURE_ALGORITHM) 39 const sign = crypto.createSign(SIGNATURE_ALGORITHM)
40 40
41 let dataString 41 let dataString: string
42 if (typeof data === 'string') { 42 if (typeof data === 'string') {
43 dataString = data 43 dataString = data
44 } else { 44 } else {
@@ -60,7 +60,7 @@ function sign (data) {
60 return signature 60 return signature
61} 61}
62 62
63function comparePassword (plainPassword, hashPassword, callback) { 63function comparePassword (plainPassword: string, hashPassword: string, callback: (err: Error, match?: boolean) => void) {
64 bcrypt.compare(plainPassword, hashPassword, function (err, isPasswordMatch) { 64 bcrypt.compare(plainPassword, hashPassword, function (err, isPasswordMatch) {
65 if (err) return callback(err) 65 if (err) return callback(err)
66 66
@@ -68,7 +68,7 @@ function comparePassword (plainPassword, hashPassword, callback) {
68 }) 68 })
69} 69}
70 70
71function createCertsIfNotExist (callback) { 71function createCertsIfNotExist (callback: (err: Error) => void) {
72 certsExist(function (err, exist) { 72 certsExist(function (err, exist) {
73 if (err) return callback(err) 73 if (err) return callback(err)
74 74
@@ -82,7 +82,7 @@ function createCertsIfNotExist (callback) {
82 }) 82 })
83} 83}
84 84
85function cryptPassword (password, callback) { 85function cryptPassword (password: string, callback: (err: Error, hash?: string) => void) {
86 bcrypt.genSalt(BCRYPT_SALT_SIZE, function (err, salt) { 86 bcrypt.genSalt(BCRYPT_SALT_SIZE, function (err, salt) {
87 if (err) return callback(err) 87 if (err) return callback(err)
88 88
@@ -92,12 +92,12 @@ function cryptPassword (password, callback) {
92 }) 92 })
93} 93}
94 94
95function getMyPrivateCert (callback) { 95function getMyPrivateCert (callback: (err: Error, privateCert: string) => void) {
96 const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME) 96 const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME)
97 fs.readFile(certPath, 'utf8', callback) 97 fs.readFile(certPath, 'utf8', callback)
98} 98}
99 99
100function getMyPublicCert (callback) { 100function getMyPublicCert (callback: (err: Error, publicCert: string) => void) {
101 const certPath = join(CONFIG.STORAGE.CERT_DIR, PUBLIC_CERT_NAME) 101 const certPath = join(CONFIG.STORAGE.CERT_DIR, PUBLIC_CERT_NAME)
102 fs.readFile(certPath, 'utf8', callback) 102 fs.readFile(certPath, 'utf8', callback)
103} 103}
@@ -116,7 +116,7 @@ export {
116 116
117// --------------------------------------------------------------------------- 117// ---------------------------------------------------------------------------
118 118
119function certsExist (callback) { 119function certsExist (callback: (err: Error, certsExist: boolean) => void) {
120 const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME) 120 const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME)
121 fs.access(certPath, function (err) { 121 fs.access(certPath, function (err) {
122 // If there is an error the certificates do not exist 122 // If there is an error the certificates do not exist
@@ -125,14 +125,14 @@ function certsExist (callback) {
125 }) 125 })
126} 126}
127 127
128function createCerts (callback) { 128function createCerts (callback: (err: Error) => void) {
129 certsExist(function (err, exist) { 129 certsExist(function (err, exist) {
130 if (err) return callback(err) 130 if (err) return callback(err)
131 131
132 if (exist === true) { 132 if (exist === true) {
133 const string = 'Certs already exist.' 133 const errorMessage = 'Certs already exist.'
134 logger.warning(string) 134 logger.warning(errorMessage)
135 return callback(new Error(string)) 135 return callback(new Error(errorMessage))
136 } 136 }
137 137
138 logger.info('Generating a RSA key...') 138 logger.info('Generating a RSA key...')