Files
mattermost-mobile/app/utils/security.ts
Daniel Espino García ea595f1ced Fix MM-46309 (#6567)
* Fix MM-46309

* Address feedback

* Update dbPath and rename server databas instead of deleting

* ios fixes

Co-authored-by: Daniel Espino <danielespino@MacBook-Pro-de-Daniel.local>
2022-08-15 10:55:54 -04:00

32 lines
927 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import CookieManager from '@react-native-cookies/cookies';
import base64 from 'base-64';
export async function getCSRFFromCookie(url: string) {
const cookies = await CookieManager.get(url, false);
return cookies.MMCSRF?.value;
}
// This has been deprecated and is only used for migrations
export const hashCode_DEPRECATED = (str: string): string => {
let hash = 0;
let i;
let chr;
if (!str || str.length === 0) {
return hash.toString();
}
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash.toString();
};
export const urlSafeBase64Encode = (str: string): string => {
return base64.encode(str).replace(/\+/g, '-').replace(/\//g, '_');
};