You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Add randomString factored out from client secret
This commit is contained in:
@@ -50,6 +50,7 @@ import Crypto from './crypto';
|
|||||||
import { isCryptoAvailable } from './crypto';
|
import { isCryptoAvailable } from './crypto';
|
||||||
import { encodeRecoveryKey, decodeRecoveryKey } from './crypto/recoverykey';
|
import { encodeRecoveryKey, decodeRecoveryKey } from './crypto/recoverykey';
|
||||||
import { keyForNewBackup, keyForExistingBackup } from './crypto/backup_password';
|
import { keyForNewBackup, keyForExistingBackup } from './crypto/backup_password';
|
||||||
|
import { randomString } from './randomstring';
|
||||||
|
|
||||||
// Disable warnings for now: we use deprecated bluebird functions
|
// Disable warnings for now: we use deprecated bluebird functions
|
||||||
// and need to migrate, but they spam the console with warnings.
|
// and need to migrate, but they spam the console with warnings.
|
||||||
@@ -3862,14 +3863,7 @@ MatrixClient.prototype.getEventMapper = function() {
|
|||||||
* @return {string} A new client secret
|
* @return {string} A new client secret
|
||||||
*/
|
*/
|
||||||
MatrixClient.prototype.generateClientSecret = function() {
|
MatrixClient.prototype.generateClientSecret = function() {
|
||||||
let ret = "";
|
return randomString(32);
|
||||||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
||||||
|
|
||||||
for (let i = 0; i < 32; i++) {
|
|
||||||
ret += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
|
|||||||
26
src/randomstring.js
Normal file
26
src/randomstring.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2018 New Vector Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function randomString(len) {
|
||||||
|
let ret = "";
|
||||||
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
|
||||||
|
for (let i = 0; i < len; ++i) {
|
||||||
|
ret += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user