forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 Merge PR DefinitelyTyped#71545 [@types/rfc2253] introduce typings f…
…or rfc2253 by @arndissler
- Loading branch information
1 parent
db65e0a
commit dad6b15
Showing
5 changed files
with
137 additions
and
0 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 @@ | ||
* | ||
!**/*.d.ts | ||
!**/*.d.cts | ||
!**/*.d.mts | ||
!**/*.d.*.ts |
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,48 @@ | ||
/// <reference types="node" /> | ||
|
||
export class DistinguishedName { | ||
constructor(rdns?: ReadonlyArray<RelativeDistinguishedName>); | ||
has(key: number | Buffer | string): boolean; | ||
get(key: number | Buffer | string): RelativeDistinguishedName; | ||
getAll(key: number | Buffer | string): RelativeDistinguishedName[]; | ||
set(key: number | Buffer | string, value: RelativeDistinguishedName | Buffer | string): number; | ||
delete(key: number | Buffer | string): RelativeDistinguishedName[]; | ||
push(rdn: RelativeDistinguishedName): number; | ||
pop(): RelativeDistinguishedName | undefined; | ||
unshift(rdn: RelativeDistinguishedName): number | undefined; | ||
shift(): RelativeDistinguishedName | undefined; | ||
count(): number; | ||
match(dn: DistinguishedName): boolean; | ||
format(): string; | ||
toString(): string; | ||
} | ||
|
||
export class RelativeDistinguishedName { | ||
constructor(map?: DistinguishedName | RelativeDistinguishedName); | ||
has(key: Buffer | string): boolean; | ||
get(key: Buffer | string): Buffer | string; | ||
set(key: Buffer | string, value: Buffer | string): void; | ||
delete(key: Buffer | string): boolean; | ||
count(): number; | ||
match(rdn: RelativeDistinguishedName): boolean; | ||
format(): string; | ||
toString(): string; | ||
} | ||
|
||
/** | ||
* Escapes an attribute key or value and returns the escaped string. | ||
* @param value The value to escape. If the value is a {@link Buffer} it will be formatted as an octothorpe (#) followed by the hexadecimal representation of each byte in the buffer. Otherwise the value will be converted to a string and escaped according to RFC 2253. | ||
*/ | ||
export function escape(value: Buffer | string): string; | ||
|
||
/** | ||
* Formats a {@link DistinguishedName} or {@link RelativeDistinguishedName} instance according to RFC 2253 and returns a UTF-8 encoded string. | ||
* @param dn The distinguished name or relative distinguished name to format as a string. | ||
*/ | ||
export function format(dn: ReadonlyArray<RelativeDistinguishedName> | DistinguishedName): string; | ||
|
||
/** | ||
* Parses an RFC 2253 string representation of a distinguished name and returns a {@link DistinguishedName} object. | ||
* @param seq A UTF-8 encoded distinguished name. | ||
*/ | ||
export function parse(seq: string): DistinguishedName; |
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,20 @@ | ||
{ | ||
"private": true, | ||
"name": "@types/rfc2253", | ||
"version": "0.2.9999", | ||
"projects": [ | ||
"https://github.com/foss-haas/rfc2253" | ||
], | ||
"dependencies": { | ||
"@types/node": "*" | ||
}, | ||
"devDependencies": { | ||
"@types/rfc2253": "workspace:." | ||
}, | ||
"owners": [ | ||
{ | ||
"name": "Arnd Issler", | ||
"githubUsername": "arndissler" | ||
} | ||
] | ||
} |
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,50 @@ | ||
import { Buffer } from "node:buffer"; | ||
import * as rfc2253 from "rfc2253"; | ||
|
||
const str = "CN=John Doe,OU=People,DC=example,DC=com"; | ||
|
||
// $ExpectType DistinguishedName | ||
const dn = rfc2253.parse(str); | ||
|
||
// $ExpectType DistinguishedName | ||
const dn2 = rfc2253.parse(str); | ||
|
||
// $ExpectType string | ||
const str2 = rfc2253.format(dn); | ||
|
||
// $ExpectType string | ||
const escapedString = rfc2253.escape("John Doe"); | ||
|
||
// $ExpectType string | ||
const escapedBuffer = rfc2253.escape(new Buffer([1, 2, 3, 16, 255])); | ||
|
||
// $ExpectType boolean | ||
dn.match(dn2); | ||
|
||
// $ExpectType DistinguishedName | ||
const distinguishedName = new rfc2253.DistinguishedName(); | ||
|
||
// $ExpectType RelativeDistinguishedName | ||
const relativeDistinguishedName = new rfc2253.RelativeDistinguishedName(); | ||
|
||
let dnWayneEnterprises = rfc2253.parse( | ||
"CN=Wayne\\, Bruce,DC=Wayne Enterprises,DC=com,OU=Research and Development,OU=Gadget Services", | ||
); | ||
|
||
// $ExpectType RelativeDistinguishedName[] | ||
const ous = dnWayneEnterprises.getAll("OU"); | ||
|
||
// @ts-expect-error | ||
const failParse = rfc2253.parse(); | ||
|
||
// @ts-expect-error | ||
const failFormat = rfc2253.format(); | ||
|
||
// @ts-expect-error | ||
const failEscape = rfc2253.escape(); | ||
|
||
// @ts-expect-error | ||
const failDistinguishedName = new rfc2253.DistinguishedName({}); | ||
|
||
// @ts-expect-error | ||
const failRelativeDistinguishedName = new rfc2253.RelativeDistinguishedName({}); |
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,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "node16", | ||
"lib": ["es6"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": ["index.d.ts", "rfc2253-tests.ts"] | ||
} |