From 9d829003b4337ce3ebdb2e584e6a2d212d119ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 28 Jan 2022 12:38:57 +0100 Subject: [PATCH] fix(calendar-sync) remove unneeded function A GUID is just a UUID v4, so let's use that. --- .../calendar-sync/web/microsoftCalendar.js | 38 ++----------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/react/features/calendar-sync/web/microsoftCalendar.js b/react/features/calendar-sync/web/microsoftCalendar.js index 23d45e774..797f5f0d4 100644 --- a/react/features/calendar-sync/web/microsoftCalendar.js +++ b/react/features/calendar-sync/web/microsoftCalendar.js @@ -3,6 +3,7 @@ import { Client } from '@microsoft/microsoft-graph-client'; import base64js from 'base64-js'; import type { Dispatch } from 'redux'; +import { v4 as uuidV4 } from 'uuid'; import { findWindows } from 'windows-iana'; import { createDeferred } from '../../../../modules/util/helpers'; @@ -153,8 +154,8 @@ export const microsoftCalendarApi = { const signInDeferred = createDeferred(); const guids = { - authState: generateGuid(), - authNonce: generateGuid() + authState: uuidV4(), + authNonce: uuidV4() }; dispatch(setCalendarAPIAuthState(guids)); @@ -339,21 +340,6 @@ function formatCalendarEntry(entry) { }; } -/** - * Generate a guid to be used for verifying token validity. - * - * @private - * @returns {string} The generated string. - */ -function generateGuid() { - const buf = new Uint16Array(8); - - window.crypto.getRandomValues(buf); - - return `${s4(buf[0])}${s4(buf[1])}-${s4(buf[2])}-${s4(buf[3])}-${ - s4(buf[4])}-${s4(buf[5])}${s4(buf[6])}${s4(buf[7])}`; -} - /** * Constructs and returns the URL to use for renewing an auth token. * @@ -582,24 +568,6 @@ function requestCalendarEvents( // eslint-disable-line max-params })); } -/** - * Converts the passed in number to a string and ensure it is at least 4 - * characters in length, prepending 0's as needed. - * - * @param {number} num - The number to pad and convert to a string. - * @private - * @returns {string} - The number converted to a string. - */ -function s4(num) { - let ret = num.toString(16); - - while (ret.length < 4) { - ret = `0${ret}`; - } - - return ret; -} - /** * Convert a Base64URL encoded string to a UTF-8 encoded string including CJK or Latin. *