Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3353023
D5506.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D5506.diff
View Options
diff --git a/services/tunnelbroker/src/Constants.h b/services/tunnelbroker/src/Constants.h
--- a/services/tunnelbroker/src/Constants.h
+++ b/services/tunnelbroker/src/Constants.h
@@ -43,13 +43,9 @@
// DeviceID
// DEVICEID_CHAR_LENGTH has to be kept in sync with deviceIDCharLength
// which is defined in web/utils/device-id.js
-// and with DEVICE_ID_CHAR_LENGTH
-// defined in native/native_rust_library/src/crypto_tools.rs
const size_t DEVICEID_CHAR_LENGTH = 64;
// DEVICEID_FORMAT_REGEX has to be kept in sync with deviceIDFormatRegex
// which is defined in web/utils/device-id.js
-// and with DEVICE_ID_FORMAT_REGEX
-// defined in native/native_rust_library/src/crypto_tools.rs
const std::regex DEVICEID_FORMAT_REGEX(
"^(ks|mobile|web):[a-zA-Z0-9]{" + std::to_string(DEVICEID_CHAR_LENGTH) +
"}$");
diff --git a/web/redux/device-id-updater.js b/web/redux/device-id-updater.js
--- a/web/redux/device-id-updater.js
+++ b/web/redux/device-id-updater.js
@@ -2,7 +2,7 @@
import * as React from 'react';
import { useDispatch, useSelector } from 'react-redux';
-import { generateDeviceID, deviceTypes } from '../utils/device-id';
+import { generateDeviceID, deviceIDTypes } from '../utils/device-id';
import { setDeviceIDActionType } from './action-types';
function DeviceIDUpdater(): null {
@@ -13,7 +13,7 @@
React.useEffect(() => {
if (hadDeviceIDRef.current !== false && !hasDeviceID) {
- const newDeviceID = generateDeviceID(deviceTypes.WEB);
+ const newDeviceID = generateDeviceID(deviceIDTypes.WEB);
dispatch({
type: setDeviceIDActionType,
payload: newDeviceID,
diff --git a/web/utils/device-id.js b/web/utils/device-id.js
--- a/web/utils/device-id.js
+++ b/web/utils/device-id.js
@@ -4,38 +4,32 @@
import { generateRandomString } from './text-utils';
-const deviceTypes = Object.freeze({
+const deviceIDTypes = Object.freeze({
KEYSERVER: 0,
WEB: 1,
MOBILE: 2,
});
-type DeviceType = $Values<typeof deviceTypes>;
+type DeviceIDType = $Values<typeof deviceIDTypes>;
const alphanumeric =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// deviceIDCharLength has to be kept in sync with DEVICEID_CHAR_LENGTH
// which is defined in services/tunnelbroker/src/Constants.h
-// and with DEVICE_ID_CHAR_LENGTH
-// defined in native/native_rust_library/src/crypto_tools.rs
const deviceIDCharLength = 64;
// deviceIDFormatRegex has to be kept in sync with DEVICEID_FORMAT_REGEX
// which is defined in services/tunnelbroker/src/Constants.h
-// and with DEVICE_ID_FORMAT_REGEX
-// defined in native/native_rust_library/src/crypto_tools.rs
const deviceIDFormatRegex: RegExp = new RegExp(
`^(ks|mobile|web):[a-zA-Z0-9]{${deviceIDCharLength.toString()}}$`,
);
-// generateDeviceID has to be kept in sync with generate_device_id
-// which is defined in native/native_rust_library/src/crypto_tools.rs
-function generateDeviceID(type: DeviceType): string {
+function generateDeviceID(type: DeviceIDType): string {
const suffix = generateRandomString(deviceIDCharLength, alphanumeric);
- if (type === deviceTypes.KEYSERVER) {
+ if (type === deviceIDTypes.KEYSERVER) {
return `ks:${suffix}`;
- } else if (type === deviceTypes.WEB) {
+ } else if (type === deviceIDTypes.WEB) {
return `web:${suffix}`;
- } else if (type === deviceTypes.MOBILE) {
+ } else if (type === deviceIDTypes.MOBILE) {
return `mobile:${suffix}`;
}
invariant(false, `Unhandled device type ${type}`);
@@ -44,6 +38,6 @@
export {
generateDeviceID,
deviceIDCharLength,
- deviceTypes,
+ deviceIDTypes,
deviceIDFormatRegex,
};
diff --git a/web/utils/device-id.test.js b/web/utils/device-id.test.js
--- a/web/utils/device-id.test.js
+++ b/web/utils/device-id.test.js
@@ -3,62 +3,64 @@
import {
generateDeviceID,
deviceIDCharLength,
- deviceTypes,
+ deviceIDTypes,
deviceIDFormatRegex,
} from './device-id';
describe('generateDeviceID', () => {
it(
- 'passed deviceTypes.KEYSERVER retruns a randomly generated string, ' +
+ 'passed deviceIDTypes.KEYSERVER retruns a randomly generated string, ' +
'subject to ^(ks|mobile|web):[a-zA-Z0-9]{DEVICEID_CHAR_LENGTH}$',
() => {
- expect(generateDeviceID(deviceTypes.KEYSERVER)).toMatch(
+ expect(generateDeviceID(deviceIDTypes.KEYSERVER)).toMatch(
deviceIDFormatRegex,
);
},
);
it(
- 'passed deviceTypes.WEB retruns a randomly generated string, ' +
+ 'passed deviceIDTypes.WEB retruns a randomly generated string, ' +
'subject to ^(ks|mobile|web):[a-zA-Z0-9]{DEVICEID_CHAR_LENGTH}$',
() => {
- expect(generateDeviceID(deviceTypes.WEB)).toMatch(deviceIDFormatRegex);
+ expect(generateDeviceID(deviceIDTypes.WEB)).toMatch(deviceIDFormatRegex);
},
);
it(
- 'passed deviceTypes.MOBILE retruns a randomly generated string, ' +
+ 'passed deviceIDTypes.MOBILE retruns a randomly generated string, ' +
'subject to ^(ks|mobile|web):[a-zA-Z0-9]{DEVICEID_CHAR_LENGTH}$',
() => {
- expect(generateDeviceID(deviceTypes.MOBILE)).toMatch(deviceIDFormatRegex);
+ expect(generateDeviceID(deviceIDTypes.MOBILE)).toMatch(
+ deviceIDFormatRegex,
+ );
},
);
it(
- 'passed deviceTypes.KEYSERVER retruns a randomly generated string, ' +
+ 'passed deviceIDTypes.KEYSERVER retruns a randomly generated string, ' +
'subject to ^(ks):[a-zA-Z0-9]{DEVICEID_CHAR_LENGTH}$',
() => {
- expect(generateDeviceID(deviceTypes.KEYSERVER)).toMatch(
+ expect(generateDeviceID(deviceIDTypes.KEYSERVER)).toMatch(
new RegExp(`^(ks):[a-zA-Z0-9]{${deviceIDCharLength.toString()}}$`),
);
},
);
it(
- 'passed deviceTypes.WEB retruns a randomly generated string, ' +
+ 'passed deviceIDTypes.WEB retruns a randomly generated string, ' +
'subject to ^(web):[a-zA-Z0-9]{DEVICEID_CHAR_LENGTH}$',
() => {
- expect(generateDeviceID(deviceTypes.WEB)).toMatch(
+ expect(generateDeviceID(deviceIDTypes.WEB)).toMatch(
new RegExp(`^(web):[a-zA-Z0-9]{${deviceIDCharLength.toString()}}$`),
);
},
);
it(
- 'passed deviceTypes.MOBILE retruns a randomly generated string, ' +
+ 'passed deviceIDTypes.MOBILE retruns a randomly generated string, ' +
'subject to ^(mobile):[a-zA-Z0-9]{DEVICEID_CHAR_LENGTH}$',
() => {
- expect(generateDeviceID(deviceTypes.MOBILE)).toMatch(
+ expect(generateDeviceID(deviceIDTypes.MOBILE)).toMatch(
new RegExp(`^(mobile):[a-zA-Z0-9]{${deviceIDCharLength.toString()}}$`),
);
},
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 7:43 AM (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574601
Default Alt Text
D5506.diff (6 KB)
Attached To
Mode
D5506: Revert "Rename deviceIDTypes to deviceTypes, add comments"
Attached
Detach File
Event Timeline
Log In to Comment