`crypto.DEFAULT_ENCODING`

Aperta
#407 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@aditya-bheke ci sta già lavorando.

Dal 23/10/2026.

  • #551 di @aditya-bheke — aperta

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript, node.js, typescript
Ambito
tooling

Direzione di ricerca

Non sono nominati file di implementazione né test. Inizia esaminando i requisiti del codemod e i riferimenti a DEP0091 e alla rimozione di Node.js; poi traccia come le migrazioni esistenti gestiscono le letture, le scritture e le chiamate a crypto. Il lavoro è completato quando il codemod copre i casi elencati, aggiunge parametri di codifica espliciti dove necessario e fornisce commenti per gli utilizzi ambigui.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

dep:20.x dep:EoL good first issue human help wanted let's do it

Description

Since crypto.DEFAULT_ENCODING is deprecated (DEP0091) and has reached End-of-Life status in Node.js v20.0.0, we should provide a codemod to replace it.

  • The codemod should remove references to crypto.DEFAULT_ENCODING.
  • The codemod should replace usage with explicit encoding parameters where needed.
  • The codemod should identify where the default encoding was being read or set.
  • The codemod should add comments suggesting explicit encoding usage.

Additional Information

Note that crypto.DEFAULT_ENCODING was removed in Node.js v20.0.0. This property only existed for compatibility with Node.js releases prior to version 0.9.3. The property allowed changing the default encoding for crypto operations, but this practice led to unpredictable behavior.

Instead of relying on a default encoding, developers should explicitly specify the encoding in each crypto operation. This makes the code more explicit and easier to understand.

Examples

Example 1: Reading DEFAULT_ENCODING

Before:

const crypto = require("node:crypto");

const encoding = crypto.DEFAULT_ENCODING;

After:

// crypto.DEFAULT_ENCODING has been removed
// Use explicit encoding in crypto operations instead
const encoding = "binary"; // or your preferred default encoding
Example 2: Setting DEFAULT_ENCODING

Before:

const crypto = require("node:crypto");

crypto.DEFAULT_ENCODING = "hex";

After:

// crypto.DEFAULT_ENCODING has been removed
// Always specify encoding explicitly in crypto operations
// For example: hash.digest("hex")
Example 3: Using DEFAULT_ENCODING in hash operations

Before:

const crypto = require("node:crypto");

crypto.DEFAULT_ENCODING = "hex";
const hash = crypto.createHash("sha256");
hash.update("some data");
const result = hash.digest(); // Uses DEFAULT_ENCODING

After:

const crypto = require("node:crypto");

const hash = crypto.createHash("sha256");
hash.update("some data");
const result = hash.digest("hex"); // Explicitly specify encoding
Example 4: Conditional encoding based on DEFAULT_ENCODING

Before:

const crypto = require("node:crypto");

const encoding = crypto.DEFAULT_ENCODING || "binary";
const hash = crypto.createHash("md5").update("data").digest(encoding);

After:

const crypto = require("node:crypto");

const encoding = "binary"; // Specify your preferred default
const hash = crypto.createHash("md5").update("data").digest(encoding);
Example 5: ESM import with DEFAULT_ENCODING

Before:

import crypto from "node:crypto";

if (crypto.DEFAULT_ENCODING === "hex") {
  // do something
}

After:

// crypto.DEFAULT_ENCODING has been removed
// Use explicit encoding parameters in crypto operations
// Consider using a constant for your application's default encoding
const DEFAULT_ENCODING = "hex";

if (DEFAULT_ENCODING === "hex") {
  // do something
}

Refs

Lingua principale
TypeScript
Stelle
85
Fork
58
Merge medio
2g 4h
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/userland-migrations

Tutte le issue di nodejs/userland-migrations

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.