1 |
|
2 |
|
3 | var assert = require('assert');
|
4 | var util = require('util');
|
5 |
|
6 | var isDN = require('./dn').DN.isDN;
|
7 | var isAttribute = require('./attribute').isAttribute;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function _assert(arg, type, name) {
|
14 | name = name || type;
|
15 | throw new assert.AssertionError({
|
16 | message: util.format('%s (%s) required', name, type),
|
17 | actual: typeof (arg),
|
18 | expected: type,
|
19 | operator: '===',
|
20 | stackStartFunction: _assert.caller
|
21 | });
|
22 | }
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function stringDN(input, name) {
|
28 | if (isDN(input) || typeof (input) === 'string')
|
29 | return;
|
30 | _assert(input, 'DN or string', name);
|
31 | }
|
32 |
|
33 | function optionalStringDN(input, name) {
|
34 | if (input === undefined || isDN(input) || typeof (input) === 'string')
|
35 | return;
|
36 | _assert(input, 'DN or string', name);
|
37 | }
|
38 |
|
39 | function optionalDN(input, name) {
|
40 | if (input !== undefined && !isDN(input))
|
41 | _assert(input, 'DN', name);
|
42 | }
|
43 |
|
44 | function optionalArrayOfAttribute(input, name) {
|
45 | if (input === undefined)
|
46 | return;
|
47 | if (!Array.isArray(input) ||
|
48 | input.some(function (v) { return !isAttribute(v); })) {
|
49 | _assert(input, 'array of Attribute', name);
|
50 | }
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | module.exports = {
|
57 | stringDN: stringDN,
|
58 | optionalStringDN: optionalStringDN,
|
59 | optionalDN: optionalDN,
|
60 | optionalArrayOfAttribute: optionalArrayOfAttribute
|
61 | };
|