-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
175 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"effect": patch | ||
--- | ||
|
||
rename ConfigSecret to Secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @since 2.0.0 | ||
*/ | ||
import type * as Equal from "./Equal.js" | ||
import * as InternalSecret from "./internal/secret.js" | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category symbols | ||
*/ | ||
export const SecretTypeId: unique symbol = InternalSecret.SecretTypeId | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category symbols | ||
*/ | ||
export type SecretTypeId = typeof SecretTypeId | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category models | ||
*/ | ||
export interface Secret extends Secret.Proto, Equal.Equal { | ||
/** @internal */ | ||
readonly raw: Array<number> | ||
} | ||
|
||
/** | ||
* @since 2.0.0 | ||
*/ | ||
export declare namespace Secret { | ||
/** | ||
* @since 2.0.0 | ||
* @category models | ||
*/ | ||
export interface Proto { | ||
readonly [SecretTypeId]: SecretTypeId | ||
} | ||
} | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category refinements | ||
*/ | ||
export const isSecret: (u: unknown) => u is Secret = InternalSecret.isSecret | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category constructors | ||
*/ | ||
export const make: (bytes: Array<number>) => Secret = InternalSecret.make | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category constructors | ||
*/ | ||
export const fromIterable: (iterable: Iterable<string>) => Secret = InternalSecret.fromIterable | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category constructors | ||
*/ | ||
export const fromString: (text: string) => Secret = InternalSecret.fromString | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category getters | ||
*/ | ||
export const value: (self: Secret) => string = InternalSecret.value | ||
|
||
/** | ||
* @since 2.0.0 | ||
* @category unsafe | ||
*/ | ||
export const unsafeWipe: (self: Secret) => void = InternalSecret.unsafeWipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as Equal from "../Equal.js" | ||
import { pipe } from "../Function.js" | ||
import * as Hash from "../Hash.js" | ||
import { hasProperty } from "../Predicate.js" | ||
import * as ReadonlyArray from "../ReadonlyArray.js" | ||
import type * as Secret from "../Secret.js" | ||
|
||
/** @internal */ | ||
const SecretSymbolKey = "effect/Secret" | ||
|
||
/** @internal */ | ||
export const SecretTypeId: Secret.SecretTypeId = Symbol.for( | ||
SecretSymbolKey | ||
) as Secret.SecretTypeId | ||
|
||
/** @internal */ | ||
export const proto = { | ||
[SecretTypeId]: SecretTypeId, | ||
[Hash.symbol](this: Secret.Secret): number { | ||
return pipe( | ||
Hash.hash(SecretSymbolKey), | ||
Hash.combine(Hash.array(this.raw)) | ||
) | ||
}, | ||
[Equal.symbol](this: Secret.Secret, that: unknown): boolean { | ||
return isSecret(that) && this.raw.length === that.raw.length && | ||
this.raw.every((v, i) => Equal.equals(v, that.raw[i])) | ||
} | ||
} | ||
|
||
/** @internal */ | ||
export const isSecret = (u: unknown): u is Secret.Secret => hasProperty(u, SecretTypeId) | ||
|
||
/** @internal */ | ||
export const make = (bytes: Array<number>): Secret.Secret => { | ||
const secret = Object.create(proto) | ||
Object.defineProperty(secret, "toString", { | ||
enumerable: false, | ||
value() { | ||
return "Secret(<redacted>)" | ||
} | ||
}) | ||
Object.defineProperty(secret, "raw", { | ||
enumerable: false, | ||
value: bytes | ||
}) | ||
return secret | ||
} | ||
|
||
/** @internal */ | ||
export const fromIterable = (iterable: Iterable<string>): Secret.Secret => | ||
make(ReadonlyArray.fromIterable(iterable).map((char) => char.charCodeAt(0))) | ||
|
||
/** @internal */ | ||
export const fromString = (text: string): Secret.Secret => { | ||
return make(text.split("").map((char) => char.charCodeAt(0))) | ||
} | ||
|
||
/** @internal */ | ||
export const value = (self: Secret.Secret): string => { | ||
return self.raw.map((byte) => String.fromCharCode(byte)).join("") | ||
} | ||
|
||
/** @internal */ | ||
export const unsafeWipe = (self: Secret.Secret): void => { | ||
for (let i = 0; i < self.raw.length; i++) { | ||
self.raw[i] = 0 | ||
} | ||
} |
Oops, something went wrong.