Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Replace base64encode with buffer (#541)

Leendert de Borstd6c1f38ce490
diff --git a/browser-extensions/chrome/src/App.tsx b/browser-extensions/chrome/src/App.tsx
index a7b4e3c7b..23c852d8d 100644
--- a/browser-extensions/chrome/src/App.tsx
+++ b/browser-extensions/chrome/src/App.tsx
@@ -7,31 +7,6 @@ import Settings from './pages/Settings';
import CredentialsList from './pages/CredentialsList';
import './styles/app.css';
-/**
- * Base64 encode
- * TODO: check other usages and make it generic.
- */
-function base64Encode(buffer: Uint8Array): string | null {
- if (!buffer || typeof buffer !== 'object') {
- console.error('Empty or invalid buffer received');
- return null;
- }
-
- try {
- // Convert object to array of numbers
- const byteArray = Object.values(buffer);
-
- // Convert to binary string
- const binary = String.fromCharCode.apply(null, byteArray as number[]);
-
- // Use btoa to encode binary string to base64
- return btoa(binary);
- } catch (error) {
- console.error('Error encoding to base64:', error);
- return null;
- }
-}
-
/**
* Main application component
*/
@@ -125,7 +100,7 @@ const App: React.FC = () => {
<Unlock />
) : (
<div>
- <CredentialsList base64Encode={base64Encode} />
+ <CredentialsList />
</div>
)}
</div>
diff --git a/browser-extensions/chrome/src/contentScript.ts b/browser-extensions/chrome/src/contentScript.ts
index b182fd0f9..a2f3328eb 100644
--- a/browser-extensions/chrome/src/contentScript.ts
+++ b/browser-extensions/chrome/src/contentScript.ts
@@ -68,10 +68,11 @@ function createPopup(input: HTMLInputElement, credentials: Credential[]) : void
// Handle base64 image data
if (cred.Logo) {
- const base64Logo = base64Encode(cred.Logo);
- if (base64Logo) {
+ try {
+ const base64Logo = Buffer.from(cred.Logo).toString('base64');
imgElement.src = `data:image/x-icon;base64,${base64Logo}`;
- } else {
+ } catch (error) {
+ console.error('Error encoding logo:', error);
imgElement.src = `data:image/x-icon;base64,${placeholderBase64}`;
}
} else {
@@ -135,28 +136,3 @@ function triggerInputEvents(element: HTMLInputElement) : void {
element.dispatchEvent(new Event('input', { bubbles: true }));
element.dispatchEvent(new Event('change', { bubbles: true }));
}
-
-/**
- * Base64 encode
- * TODO: make this a generic function if still needed? Check all other usages.
- */
-function base64Encode(buffer: Uint8Array): string | null {
- if (!buffer || typeof buffer !== 'object') {
- console.error('Empty or invalid buffer received');
- return null;
- }
-
- try {
- // Convert object to array of numbers
- const byteArray = Object.values(buffer);
-
- // Convert to binary string
- const binary = String.fromCharCode.apply(null, byteArray as number[]);
-
- // Use btoa to encode binary string to base64
- return btoa(binary);
- } catch (error) {
- console.error('Error encoding to base64:', error);
- return null;
- }
-}
diff --git a/browser-extensions/chrome/src/pages/CredentialsList.tsx b/browser-extensions/chrome/src/pages/CredentialsList.tsx
index f7048efc5..7f047f211 100644
--- a/browser-extensions/chrome/src/pages/CredentialsList.tsx
+++ b/browser-extensions/chrome/src/pages/CredentialsList.tsx
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
import { useDb } from '../context/DbContext';
+import { Buffer } from 'buffer';
type Credential = {
Id: string;
@@ -49,7 +50,7 @@ const CredentialsList: React.FC<CredentialsListProps> = ({ base64Encode }) => {
{credentials.map(cred => (
<li key={cred.Id} className="p-2 border dark:border-gray-600 rounded flex items-center bg-gray-50 dark:bg-gray-800">
<img
- src={cred.Logo ? `data:image/x-icon;base64,${base64Encode(cred.Logo)}` : '/assets/images/service-placeholder.webp'}
+ src={cred.Logo ? `data:image/x-icon;base64,${Buffer.from(cred.Logo).toString('base64')}` : '/assets/images/service-placeholder.webp'}
alt={cred.ServiceName}
className="w-8 h-8 mr-2 flex-shrink-0"
onError={(e) => {