Skip to content

Commit dad6b15

Browse files
authored
🤖 Merge PR DefinitelyTyped#71545 [@types/rfc2253] introduce typings for rfc2253 by @arndissler
1 parent db65e0a commit dad6b15

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

‎types/rfc2253/.npmignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

‎types/rfc2253/index.d.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/// <reference types="node" />
2+
3+
export class DistinguishedName {
4+
constructor(rdns?: ReadonlyArray<RelativeDistinguishedName>);
5+
has(key: number | Buffer | string): boolean;
6+
get(key: number | Buffer | string): RelativeDistinguishedName;
7+
getAll(key: number | Buffer | string): RelativeDistinguishedName[];
8+
set(key: number | Buffer | string, value: RelativeDistinguishedName | Buffer | string): number;
9+
delete(key: number | Buffer | string): RelativeDistinguishedName[];
10+
push(rdn: RelativeDistinguishedName): number;
11+
pop(): RelativeDistinguishedName | undefined;
12+
unshift(rdn: RelativeDistinguishedName): number | undefined;
13+
shift(): RelativeDistinguishedName | undefined;
14+
count(): number;
15+
match(dn: DistinguishedName): boolean;
16+
format(): string;
17+
toString(): string;
18+
}
19+
20+
export class RelativeDistinguishedName {
21+
constructor(map?: DistinguishedName | RelativeDistinguishedName);
22+
has(key: Buffer | string): boolean;
23+
get(key: Buffer | string): Buffer | string;
24+
set(key: Buffer | string, value: Buffer | string): void;
25+
delete(key: Buffer | string): boolean;
26+
count(): number;
27+
match(rdn: RelativeDistinguishedName): boolean;
28+
format(): string;
29+
toString(): string;
30+
}
31+
32+
/**
33+
* Escapes an attribute key or value and returns the escaped string.
34+
* @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.
35+
*/
36+
export function escape(value: Buffer | string): string;
37+
38+
/**
39+
* Formats a {@link DistinguishedName} or {@link RelativeDistinguishedName} instance according to RFC 2253 and returns a UTF-8 encoded string.
40+
* @param dn The distinguished name or relative distinguished name to format as a string.
41+
*/
42+
export function format(dn: ReadonlyArray<RelativeDistinguishedName> | DistinguishedName): string;
43+
44+
/**
45+
* Parses an RFC 2253 string representation of a distinguished name and returns a {@link DistinguishedName} object.
46+
* @param seq A UTF-8 encoded distinguished name.
47+
*/
48+
export function parse(seq: string): DistinguishedName;

‎types/rfc2253/package.json‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"private": true,
3+
"name": "@types/rfc2253",
4+
"version": "0.2.9999",
5+
"projects": [
6+
"https://github.com/foss-haas/rfc2253"
7+
],
8+
"dependencies": {
9+
"@types/node": "*"
10+
},
11+
"devDependencies": {
12+
"@types/rfc2253": "workspace:."
13+
},
14+
"owners": [
15+
{
16+
"name": "Arnd Issler",
17+
"githubUsername": "arndissler"
18+
}
19+
]
20+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Buffer } from "node:buffer";
2+
import * as rfc2253 from "rfc2253";
3+
4+
const str = "CN=John Doe,OU=People,DC=example,DC=com";
5+
6+
// $ExpectType DistinguishedName
7+
const dn = rfc2253.parse(str);
8+
9+
// $ExpectType DistinguishedName
10+
const dn2 = rfc2253.parse(str);
11+
12+
// $ExpectType string
13+
const str2 = rfc2253.format(dn);
14+
15+
// $ExpectType string
16+
const escapedString = rfc2253.escape("John Doe");
17+
18+
// $ExpectType string
19+
const escapedBuffer = rfc2253.escape(new Buffer([1, 2, 3, 16, 255]));
20+
21+
// $ExpectType boolean
22+
dn.match(dn2);
23+
24+
// $ExpectType DistinguishedName
25+
const distinguishedName = new rfc2253.DistinguishedName();
26+
27+
// $ExpectType RelativeDistinguishedName
28+
const relativeDistinguishedName = new rfc2253.RelativeDistinguishedName();
29+
30+
let dnWayneEnterprises = rfc2253.parse(
31+
"CN=Wayne\\, Bruce,DC=Wayne Enterprises,DC=com,OU=Research and Development,OU=Gadget Services",
32+
);
33+
34+
// $ExpectType RelativeDistinguishedName[]
35+
const ous = dnWayneEnterprises.getAll("OU");
36+
37+
// @ts-expect-error
38+
const failParse = rfc2253.parse();
39+
40+
// @ts-expect-error
41+
const failFormat = rfc2253.format();
42+
43+
// @ts-expect-error
44+
const failEscape = rfc2253.escape();
45+
46+
// @ts-expect-error
47+
const failDistinguishedName = new rfc2253.DistinguishedName({});
48+
49+
// @ts-expect-error
50+
const failRelativeDistinguishedName = new rfc2253.RelativeDistinguishedName({});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": ["es6"],
5+
"noImplicitAny": true,
6+
"noImplicitThis": true,
7+
"strictFunctionTypes": true,
8+
"strictNullChecks": true,
9+
"types": [],
10+
"noEmit": true,
11+
"forceConsistentCasingInFileNames": true
12+
},
13+
"files": ["index.d.ts", "rfc2253-tests.ts"]
14+
}

0 commit comments

Comments
 (0)