File

src/auth/providers/hashing.provider.ts

Description

HashingProvider is an abstract class that defines the interface for hashing services. It provides methods to hash data and compare it against a hash. Implementations of this provider can use different hashing algorithms.

Index

Methods

Methods

Abstract compare
compare(data: string | Buffer, hash: string)

Compares the provided data against a hash to verify if they match.

Parameters :
Name Type Optional Description
data string | Buffer No
  • The data to compare, can be a string or Buffer.
hash string No
  • The hash to compare against.
Returns : Promise<boolean>

A promise that resolves to true if the data matches the hash, false otherwise.

Abstract hash
hash(data: string | Buffer)

Hashes the provided data using a specific hashing algorithm.

Parameters :
Name Type Optional Description
data string | Buffer No
  • The data to be hashed, can be a string or Buffer.
Returns : Promise<string>

A promise that resolves to the hashed string.

import { Injectable } from '@nestjs/common';

/**
 * HashingProvider is an abstract class that defines the interface for hashing services.
 * It provides methods to hash data and compare it against a hash.
 * Implementations of this provider can use different hashing algorithms.
 */
@Injectable()
export abstract class HashingProvider {
  /**
   * Hashes the provided data using a specific hashing algorithm.
   * @param data - The data to be hashed, can be a string or Buffer.
   * @returns A promise that resolves to the hashed string.
   */
  abstract hash(data: string | Buffer): Promise<string>;

  /**
   * Compares the provided data against a hash to verify if they match.
   * @param data - The data to compare, can be a string or Buffer.
   * @param hash - The hash to compare against.
   * @returns A promise that resolves to true if the data matches the hash, false otherwise.
   */
  abstract compare(data: string | Buffer, hash: string): Promise<boolean>;
}

results matching ""

    No results matching ""