diff --git a/lib/cms/recipientInfo.ts b/lib/cms/recipientInfo.ts index e905cab..9c4e34a 100644 --- a/lib/cms/recipientInfo.ts +++ b/lib/cms/recipientInfo.ts @@ -12,29 +12,11 @@ namespace trusted.cms { export class CmsRecipientInfo extends BaseObject { /** * Creates an instance of CmsRecipientInfo. - * - * - * @memberOf CmsRecipientInfo - */ - constructor(); - - /** - * Creates an instance of CmsRecipientInfo. - * - * @param {native.CMS.CmsRecipientInfo} handle - * - * @memberOf CmsRecipientInfo - */ - constructor(handle: native.CMS.CmsRecipientInfo); - - /** - * Creates an instance of CmsRecipientInfo. - * - * @param {*} [param] + * @param {native.CMS.CmsRecipientInfo} [param] * * @memberOf CmsRecipientInfo */ - constructor(param?: any) { + constructor(param?: native.CMS.CmsRecipientInfo) { super(); if (param instanceof native.CMS.CmsRecipientInfo) { this.handle = param; @@ -74,7 +56,7 @@ namespace trusted.cms { * @memberOf CmsRecipientInfo */ public ktriCertCmp(cert: pki.Certificate): number { - let cmp: any = this.handle.ktriCertCmp(cert.handle); + const cmp: number = this.handle.ktriCertCmp(cert.handle); if (cmp < 0) { return -1; } diff --git a/lib/cms/recipientInfos.ts b/lib/cms/recipientInfos.ts index 6ca4c82..2fd150d 100644 --- a/lib/cms/recipientInfos.ts +++ b/lib/cms/recipientInfos.ts @@ -14,29 +14,11 @@ namespace trusted.cms { implements core.ICollectionWrite { /** * Creates an instance of CmsRecipientInfoCollection. - * - * - * @memberOf CmsRecipientInfoCollection - */ - constructor(); - - /** - * Creates an instance of CmsRecipientInfoCollection. - * - * @param {native.CMS.CmsRecipientInfoCollection} handle - * - * @memberOf CmsRecipientInfoCollection - */ - constructor(handle: native.CMS.CmsRecipientInfoCollection); - - /** - * Creates an instance of CmsRecipientInfoCollection. - * - * @param {*} [param] + * @param {native.CMS.CmsRecipientInfoCollection} [param] * * @memberOf CmsRecipientInfoCollection */ - constructor(param?: any) { + constructor(param?: native.CMS.CmsRecipientInfoCollection) { super(); if (param instanceof native.CMS.CmsRecipientInfoCollection) { this.handle = param; diff --git a/lib/cms/signed_data.ts b/lib/cms/signed_data.ts index 900d7a7..3c76aab 100644 --- a/lib/cms/signed_data.ts +++ b/lib/cms/signed_data.ts @@ -54,7 +54,7 @@ namespace trusted.cms { function EnumGetName(e: any, name: string): any { "use strict"; - for (let i in e) { + for (const i in e) { if (i.toString().toLowerCase() === name.toLowerCase()) { return { name: i, value: e[i] }; } @@ -81,7 +81,7 @@ namespace trusted.cms { * @memberOf SignedData */ public static load(filename: string, format: DataFormat = DEFAULT_DATA_FORMAT): SignedData { - let cms: SignedData = new SignedData(); + const cms: SignedData = new SignedData(); cms.handle.load(filename, format); return cms; } @@ -97,7 +97,7 @@ namespace trusted.cms { * @memberOf SignedData */ public static import(buffer: Buffer, format: DataFormat = DEFAULT_DATA_FORMAT): SignedData { - let cms: SignedData = new SignedData(); + const cms: SignedData = new SignedData(); cms.handle.import(buffer, format); return cms; } @@ -125,7 +125,7 @@ namespace trusted.cms { get content(): ISignedDataContent { if (!this.prContent && !this.isDetached()) { // Извлечь содержимое из подписи - let buf: Buffer = this.handle.getContent(); + const buf: Buffer = this.handle.getContent(); this.prContent = { data: buf, type: SignedDataContentType.buffer, @@ -145,7 +145,7 @@ namespace trusted.cms { if (v.type === SignedDataContentType.url) { data = v.data.toString(); } else { - data = new Buffer( v.data); + data = new Buffer(v.data as any); } this.handle.setContent(data); this.prContent = v; @@ -158,11 +158,11 @@ namespace trusted.cms { * @memberOf SignedData */ get policies(): string[] { - let p: string[] = new Array(); + const p: string[] = new Array(); - let flags: number = this.handle.getFlags(); + const flags: number = this.handle.getFlags(); - for (let i in SignedDataPolicy) { + for (const i in SignedDataPolicy) { if (+i & flags) { p.push(SignedDataPolicy[i]); } @@ -179,8 +179,8 @@ namespace trusted.cms { */ set policies(v: string[]) { let flags: number = 0; - for (let i: number = 0; i < v.length; i++) { - let flag: any = EnumGetName(SignedDataPolicy, v[i]); + for (const item of v) { + const flag: any = EnumGetName(SignedDataPolicy, item); if (flag) { flags |= +flag.value; } @@ -228,7 +228,7 @@ namespace trusted.cms { * @memberOf SignedData */ public certificates(index?: number): any { - let certs: pki.CertificateCollection = new pki.CertificateCollection(this.handle.getCertificates()); + const certs: pki.CertificateCollection = new pki.CertificateCollection(this.handle.getCertificates()); if (index !== undefined) { return certs.items(index); } @@ -263,7 +263,7 @@ namespace trusted.cms { * @memberOf SignedData */ public signers(index?: number): any { - let signers: SignerCollection = new SignerCollection(this.handle.getSigners()); + const signers: SignerCollection = new SignerCollection(this.handle.getSigners()); if (index !== undefined) { return signers.items(index); } @@ -328,7 +328,7 @@ namespace trusted.cms { * @memberOf SignedData */ public createSigner(cert: pki.Certificate, key: pki.Key): Signer { - let signer: any = this.handle.createSigner(cert.handle, key.handle); + const signer: any = this.handle.createSigner(cert.handle, key.handle); return new Signer(signer); } diff --git a/lib/cms/signer.ts b/lib/cms/signer.ts index 192380b..ce3baea 100644 --- a/lib/cms/signer.ts +++ b/lib/cms/signer.ts @@ -54,7 +54,7 @@ namespace trusted.cms { * @memberOf Signer */ get digestAlgorithm(): Algorithm { - let alg: Algorithm = new pki.Algorithm(this.handle.getDigestAlgorithm()); + const alg: Algorithm = new pki.Algorithm(this.handle.getDigestAlgorithm()); return alg; } @@ -83,7 +83,7 @@ namespace trusted.cms { if (v.type === SignedDataContentType.url) { data = v.data.toString(); } else { - data = new Buffer( v.data); + data = new Buffer(v.data as any); } } return this.handle.verifyContent(data); @@ -128,7 +128,7 @@ namespace trusted.cms { * @memberOf Signer */ public signedAttributes(index?: number): any { - let attrs: SignerAttributeCollection = new SignerAttributeCollection(this.handle.getSignedAttributes()); + const attrs: SignerAttributeCollection = new SignerAttributeCollection(this.handle.getSignedAttributes()); if (index === undefined) { return attrs; @@ -165,7 +165,7 @@ namespace trusted.cms { * @memberOf Signer */ public unsignedAttributes(index?: number): any { - let attrs: SignerAttributeCollection = new SignerAttributeCollection(this.handle.getUnsignedAttributes()); + const attrs: SignerAttributeCollection = new SignerAttributeCollection(this.handle.getUnsignedAttributes()); if (index === undefined) { return attrs; diff --git a/lib/cms/signer_id.ts b/lib/cms/signer_id.ts index 81d2193..452514a 100644 --- a/lib/cms/signer_id.ts +++ b/lib/cms/signer_id.ts @@ -12,11 +12,11 @@ namespace trusted.cms { export class SignerId extends BaseObject { /** * Creates an instance of SignerId. - * + * @param {native.CMS.SignerId} [param] * * @memberOf SignerId */ - constructor(param?: any) { + constructor(param?: native.CMS.SignerId) { super(); if (param instanceof native.CMS.SignerId) { this.handle = param; diff --git a/lib/common/openssl.ts b/lib/common/openssl.ts index 9b57e7a..9aef77c 100644 --- a/lib/common/openssl.ts +++ b/lib/common/openssl.ts @@ -19,7 +19,7 @@ namespace trusted.common { * @memberOf OpenSSL */ public static run(): void { - let openssl = new native.COMMON.OpenSSL(); + const openssl = new native.COMMON.OpenSSL(); return openssl.run(); } @@ -32,7 +32,7 @@ namespace trusted.common { * @memberOf OpenSSL */ public static stop(): void { - let openssl = new native.COMMON.OpenSSL(); + const openssl = new native.COMMON.OpenSSL(); return openssl.stop(); } @@ -45,7 +45,7 @@ namespace trusted.common { * @memberOf OpenSSL */ public static printErrors(): string { - let openssl = new native.COMMON.OpenSSL(); + const openssl = new native.COMMON.OpenSSL(); return openssl.printErrors(); } @@ -58,6 +58,6 @@ namespace trusted.common { constructor() { super(); this.handle = new native.COMMON.OpenSSL(); - }; + } } } diff --git a/lib/logger_level.ts b/lib/logger_level.ts index ed1705f..26148bd 100644 --- a/lib/logger_level.ts +++ b/lib/logger_level.ts @@ -13,6 +13,6 @@ namespace trusted { DEBUG = 8, TRACE = 16, OPENSSL = 32, - ALL = ERROR | WARNING | INFO | DEBUG | TRACE | OPENSSL - } + // tslint:disable-next-line:no-bitwise + ALL = ERROR | WARNING | INFO | DEBUG | TRACE | OPENSSL} } diff --git a/lib/native.ts b/lib/native.ts index 1987c05..c6dcb72 100644 --- a/lib/native.ts +++ b/lib/native.ts @@ -17,8 +17,7 @@ declare namespace native { } class Algorithm { - constructor(); - constructor(name: string); + constructor(name?: string); public getTypeId(): OID; public getName(): string; public duplicate(): Algorithm; @@ -45,8 +44,7 @@ declare namespace native { } class OID { - constructor(); - constructor(value: string); + constructor(value?: string); public getLongName(): string; public getShortName(): string; public getValue(): string; @@ -143,8 +141,7 @@ declare namespace native { } class CertificationRequest { - constructor(); - constructor(csrinfo: PKI.CertificationRequestInfo); + constructor(csrinfo?: PKI.CertificationRequestInfo); public load(filename: string, dataFormat: trusted.DataFormat): void; public sign(key: Key): void; public verify(): boolean; @@ -188,7 +185,7 @@ declare namespace native { public getCrlLocal(cert: Certificate, store: PKISTORE.PkiStore): any; public getCrlDistPoints(cert: Certificate): string[]; public checkCrlTime(crl: CRL): boolean; - public downloadCRL(distPoints: string[], path: string, done: Function): void; + public downloadCRL(distPoints: string[], path: string, done: (err: Error, crl: PKI.CRL) => void): void; } class Pkcs12 { @@ -404,8 +401,7 @@ declare namespace native { public save(fileName: string); public load(fileName: string); public export(): IPkiItem[]; - public import(items: IPkiItem[]); - public import(item: PkiItem); + public import(items: IPkiItem[] | PkiItem); } class Filter { @@ -453,7 +449,7 @@ declare namespace native { class Cerber { public sign(modulePath: string, cert: PKI.Certificate, key: PKI.Key): void; - public verify(modulePath: string, cacerts?: PKI.CertificateCollection): Object; + public verify(modulePath: string, cacerts?: PKI.CertificateCollection): object; } class Logger { diff --git a/lib/object.ts b/lib/object.ts index c78ce05..54ff4b9 100644 --- a/lib/object.ts +++ b/lib/object.ts @@ -9,9 +9,9 @@ namespace trusted { throw TypeError("BaseObjectCheck::Wrong incoming object for wrap function"); } - let newObj: any = new this(); + const newObj: any = new this(); newObj.handle = obj; - return newObj; + return newObj as TOut; } public handle: T; diff --git a/lib/pki/alg.ts b/lib/pki/alg.ts index 2b11fec..c2f99cb 100644 --- a/lib/pki/alg.ts +++ b/lib/pki/alg.ts @@ -13,38 +13,11 @@ namespace trusted.pki { export class Algorithm extends BaseObject { /** * Creates an instance of Algorithm. - * - * - * @memberOf Algorithm - */ - constructor(); - - /** - * Creates an instance of Algorithm. - * - * @param {native.PKI.Algorithm} handle - * - * @memberOf Algorithm - */ - constructor(handle: native.PKI.Algorithm); - - /** - * Creates an instance of Algorithm. - * - * @param {string} name - * - * @memberOf Algorithm - */ - constructor(name: string); - - /** - * Creates an instance of Algorithm. - * - * @param {*} [param] + * @param {(native.PKI.Algorithm | string)} [param] * * @memberOf Algorithm */ - constructor (param?: any) { + constructor(param?: native.PKI.Algorithm | string) { super(); if (param instanceof native.PKI.Algorithm) { @@ -86,8 +59,8 @@ namespace trusted.pki { * @memberOf Algorithm */ public duplicate(): Algorithm { - let walg: any = this.handle.duplicate(); - let alg: any = new Algorithm(); + const walg: any = this.handle.duplicate(); + const alg: any = new Algorithm(); alg.handle = walg; return alg; } diff --git a/lib/pki/attr.ts b/lib/pki/attr.ts index 78443a3..6381caa 100644 --- a/lib/pki/attr.ts +++ b/lib/pki/attr.ts @@ -14,21 +14,11 @@ namespace trusted.pki { /** * Creates an instance of Attribute. - * - * @param {native.PKI.Attribute} handle - * - * @memberOf Attribute - */ - constructor(handle: native.PKI.Attribute); - - /** - * Creates an instance of Attribute. - * - * @param {*} [param] + * @param {native.PKI.Attribute} [param] * * @memberOf Attribute */ - constructor(param?: any) { + constructor(param?: native.PKI.Attribute) { super(); if (param instanceof native.PKI.Attribute) { this.handle = param; @@ -87,8 +77,8 @@ namespace trusted.pki { * @memberOf Attribute */ public duplicate(): Attribute { - let nattr: any = this.handle.duplicate(); - let attr: Attribute = Attribute.wrap(nattr); + const nattr: any = this.handle.duplicate(); + const attr: Attribute = Attribute.wrap(nattr); return attr; } @@ -132,8 +122,8 @@ namespace trusted.pki { * @memberOf Attribute */ public values(index?: number): any { - let vals: any = this.handle.values(); - let attrVals: AttributeValueCollection = + const vals: any = this.handle.values(); + const attrVals: AttributeValueCollection = AttributeValueCollection.wrap(vals); if (index === undefined) { diff --git a/lib/pki/cert.ts b/lib/pki/cert.ts index 71bf5bc..2304989 100644 --- a/lib/pki/cert.ts +++ b/lib/pki/cert.ts @@ -24,7 +24,7 @@ namespace trusted.pki { * @memberOf Certificate */ public static load(filename: string, format: DataFormat = DEFAULT_DATA_FORMAT): Certificate { - let cert: Certificate = new Certificate(); + const cert: Certificate = new Certificate(); cert.handle.load(filename, format); return cert; } @@ -40,36 +40,18 @@ namespace trusted.pki { * @memberOf Certificate */ public static import(buffer: Buffer, format: DataFormat = DEFAULT_DATA_FORMAT): Certificate { - let cert: Certificate = new Certificate(); + const cert: Certificate = new Certificate(); cert.handle.import(buffer, format); return cert; } /** * Creates an instance of Certificate. - * - * - * @memberOf Certificate - */ - constructor(); - - /** - * Creates an instance of Certificate. - * - * @param {native.PKI.Certificate} handle - * - * @memberOf Certificate - */ - constructor(handle: native.PKI.Certificate); - - /** - * Creates an instance of Certificate. - * - * @param {*} [param] + * @param {native.PKI.Certificate} [param] * * @memberOf Certificate */ - constructor(param?: any) { + constructor(param?: native.PKI.Certificate) { super(); if (param instanceof native.PKI.Certificate) { this.handle = param; @@ -252,7 +234,7 @@ namespace trusted.pki { * @memberOf Certificate */ public compare(cert: Certificate): number { - let cmp: any = this.handle.compare(cert.handle); + const cmp: any = this.handle.compare(cert.handle); if (cmp < 0) { return -1; } @@ -283,7 +265,7 @@ namespace trusted.pki { * * @memberOf Certificate */ - public hash(algorithm: string = "sha1"): String { + public hash(algorithm: string = "sha1"): string { return this.handle.hash(algorithm).toString("hex"); } @@ -295,7 +277,7 @@ namespace trusted.pki { * @memberOf Certificate */ public duplicate(): Certificate { - let cert: Certificate = new Certificate(); + const cert: Certificate = new Certificate(); cert.handle = this.handle.duplicate(); return cert; } diff --git a/lib/pki/certReq.ts b/lib/pki/certReq.ts index 909cca7..0bce393 100644 --- a/lib/pki/certReq.ts +++ b/lib/pki/certReq.ts @@ -25,36 +25,18 @@ namespace trusted.pki { * @memberOf CertificationRequest */ public static load(filename: string, format: DataFormat = DEFAULT_DATA_FORMAT): CertificationRequest { - let req: CertificationRequest = new CertificationRequest(); + const req: CertificationRequest = new CertificationRequest(); req.handle.load(filename, format); return req; } /** * Creates an instance of CertificationRequest. - * - * - * @memberOf CertificationRequest - */ - constructor(); - - /** - * Creates an instance of CertificationRequest. - * - * @param {native.PKI.CertificationRequest} handle - * - * @memberOf CertificationRequest - */ - constructor(handle: native.PKI.CertificationRequest); - - /** - * Creates an instance of CertificationRequest. - * - * @param {*} [param] + * @param {native.PKI.CertificationRequest} [param] * * @memberOf CertificationRequest */ - constructor(param?: any) { + constructor(param?: native.PKI.CertificationRequest) { super(); if (param instanceof native.PKI.CertificationRequestInfo) { this.handle = new native.PKI.CertificationRequest(param); diff --git a/lib/pki/certReqInfo.ts b/lib/pki/certReqInfo.ts index ef61963..dbbae91 100644 --- a/lib/pki/certReqInfo.ts +++ b/lib/pki/certReqInfo.ts @@ -14,29 +14,11 @@ namespace trusted.pki { /** * Creates an instance of CertificationRequestInfo. - * - * - * @memberOf CertificationRequestInfo - */ - constructor(); - - /** - * Creates an instance of CertificationRequestInfo. - * - * @param {native.PKI.CertificationRequestInfo} handle - * - * @memberOf CertificationRequestInfo - */ - constructor(handle: native.PKI.CertificationRequestInfo); - - /** - * Creates an instance of CertificationRequestInfo. - * - * @param {*} [param] + * @param {native.PKI.CertificationRequestInfo} [param] * * @memberOf CertificationRequestInfo */ - constructor(param?: any) { + constructor(param?: native.PKI.CertificationRequestInfo) { super(); if (param instanceof native.PKI.CertificationRequestInfo) { diff --git a/lib/pki/certs.ts b/lib/pki/certs.ts index 7157113..6937e59 100644 --- a/lib/pki/certs.ts +++ b/lib/pki/certs.ts @@ -15,29 +15,11 @@ namespace trusted.pki { /** * Creates an instance of CertificateCollection. - * - * @param {native.PKI.CertificateCollection} handle - * - * @memberOf CertificateCollection - */ - constructor(handle: native.PKI.CertificateCollection); - - /** - * Creates an instance of CertificateCollection. - * - * - * @memberOf CertificateCollection - */ - constructor(); - - /** - * Creates an instance of CertificateCollection. - * - * @param {*} [param] + * @param {native.PKI.CertificateCollection} [param] * * @memberOf CertificateCollection */ - constructor(param?: any) { + constructor(param?: native.PKI.CertificateCollection) { super(); if (param instanceof native.PKI.CertificateCollection) { this.handle = param; diff --git a/lib/pki/chain.ts b/lib/pki/chain.ts index 564f9e2..56cb25e 100644 --- a/lib/pki/chain.ts +++ b/lib/pki/chain.ts @@ -33,7 +33,7 @@ namespace trusted.pki { * @memberOf Chain */ public buildChain(cert: Certificate, certs: CertificateCollection): CertificateCollection { - let certscol: CertificateCollection = + const certscol: CertificateCollection = new CertificateCollection(this.handle.buildChain(cert.handle, certs.handle)); return certscol; } diff --git a/lib/pki/cipher.ts b/lib/pki/cipher.ts index 5eb81f1..efa21e9 100644 --- a/lib/pki/cipher.ts +++ b/lib/pki/cipher.ts @@ -124,15 +124,15 @@ namespace trusted.pki { this.handle.setSalt(salt); } - get algorithm(): String { + get algorithm(): string { return this.handle.getAlgorithm(); } - get mode(): String { + get mode(): string { return this.handle.getMode(); } - get dgst(): String { + get dgst(): string { return this.handle.getDigestAlgorithm(); } diff --git a/lib/pki/crl.ts b/lib/pki/crl.ts index 6df238a..6c50a65 100644 --- a/lib/pki/crl.ts +++ b/lib/pki/crl.ts @@ -24,7 +24,7 @@ namespace trusted.pki { * @memberOf Crl */ public static load(filename: string, format: DataFormat = DEFAULT_DATA_FORMAT): Crl { - let crl: Crl = new Crl(); + const crl: Crl = new Crl(); crl.load(filename, format); return crl; } @@ -40,36 +40,18 @@ namespace trusted.pki { * @memberOf Crl */ public static import(buffer: Buffer, format: DataFormat = DEFAULT_DATA_FORMAT): Crl { - let crl: Crl = new Crl(); + const crl: Crl = new Crl(); crl.import(buffer, format); return crl; } /** * Creates an instance of Crl. - * - * - * @memberOf Crl - */ - constructor(); - - /** - * Creates an instance of Crl. - * - * @param {native.PKI.CRL} handle - * - * @memberOf Crl - */ - constructor(handle: native.PKI.CRL); - - /** - * Creates an instance of Crl. - * - * @param {*} [param] + * @param {native.PKI.CRL} [param] * * @memberOf Crl */ - constructor(param?: any) { + constructor(param?: native.PKI.CRL) { super(); if (param instanceof native.PKI.CRL) { this.handle = param; @@ -267,7 +249,7 @@ namespace trusted.pki { * @memberOf Crl */ public compare(crl: Crl): number { - let cmp: number = this.handle.compare(crl.handle); + const cmp: number = this.handle.compare(crl.handle); if (cmp < 0) { return -1; } @@ -298,7 +280,7 @@ namespace trusted.pki { * * @memberOf Crl */ - public hash(algorithm: string = "sha1"): String { + public hash(algorithm: string = "sha1"): string { return this.handle.hash(algorithm).toString("hex"); } @@ -310,7 +292,7 @@ namespace trusted.pki { * @memberOf Crl */ public duplicate(): Crl { - let crl: Crl = new Crl(); + const crl: Crl = new Crl(); crl.handle = this.handle.duplicate(); return crl; } diff --git a/lib/pki/crls.ts b/lib/pki/crls.ts index 1f5e91c..7d7eec6 100644 --- a/lib/pki/crls.ts +++ b/lib/pki/crls.ts @@ -12,31 +12,14 @@ namespace trusted.pki { * @implements {core.ICollectionWrite} */ export class CrlCollection extends BaseObject implements core.ICollectionWrite { - /** - * Creates an instance of CrlCollection. - * - * @param {native.PKI.CrlCollection} handle - * - * @memberOf CrlCollection - */ - constructor(handle: native.PKI.CrlCollection); - - /** - * Creates an instance of CrlCollection. - * - * - * @memberOf CrlCollection - */ - constructor(); /** * Creates an instance of CrlCollection. - * - * @param {*} [param] + * @param {native.PKI.CrlCollection} [param] * * @memberOf CrlCollection */ - constructor(param?: any) { + constructor(param?: native.PKI.CrlCollection) { super(); if (param instanceof native.PKI.CrlCollection) { this.handle = param; diff --git a/lib/pki/key.ts b/lib/pki/key.ts index 7eb5992..a6557c4 100644 --- a/lib/pki/key.ts +++ b/lib/pki/key.ts @@ -23,7 +23,7 @@ namespace trusted.pki { * @memberOf Key */ public static readPrivateKey(filename: string, format: DataFormat, password: string): Key { - let key: Key = new Key(); + const key: Key = new Key(); key.readPrivateKey.apply(key, arguments); return Key.wrap(key.handle); } @@ -39,36 +39,18 @@ namespace trusted.pki { * @memberOf Key */ public static readPublicKey(filename: string, format: DataFormat): Key { - let key: Key = new Key(); + const key: Key = new Key(); key.readPublicKey.apply(key, arguments); return Key.wrap(key.handle); } /** * Creates an instance of Key. - * - * - * @memberOf Key - */ - constructor(); - - /** - * Creates an instance of Key. - * - * @param {native.PKI.Key} handle - * - * @memberOf Key - */ - constructor(handle: native.PKI.Key); - - /** - * Creates an instance of Key. - * - * @param {*} [param] + * @param {native.PKI.Key} [param] * * @memberOf Key */ - constructor(param?: any) { + constructor(param?: native.PKI.Key) { super(); if (param instanceof native.PKI.Key) { this.handle = param; @@ -155,7 +137,7 @@ namespace trusted.pki { * @memberOf Key */ public compare(key: Key): number { - let cmp: number = this.handle.compare(key.handle); + const cmp: number = this.handle.compare(key.handle); if (cmp < 0) { return -1; } diff --git a/lib/pki/oid.ts b/lib/pki/oid.ts index 7cf48a8..267c068 100644 --- a/lib/pki/oid.ts +++ b/lib/pki/oid.ts @@ -11,33 +11,13 @@ namespace trusted.pki { * @extends {BaseObject} */ export class Oid extends BaseObject { - - /** - * Creates an instance of Oid. - * - * @param {native.PKI.OID} handle - * - * @memberOf Oid - */ - constructor(handle: native.PKI.OID); - /** * Creates an instance of Oid. - * - * @param {string} oid - * - * @memberOf Oid - */ - constructor(oid: string); - - /** - * Creates an instance of Oid. - * - * @param {*} param + * @param {(native.PKI.OID | string)} param * * @memberOf Oid */ - constructor(param: any) { + constructor(param: native.PKI.OID | string) { super(); if (typeof (param) === "string") { this.handle = new native.PKI.OID(param); diff --git a/lib/pki/pkcs12.ts b/lib/pki/pkcs12.ts index 2e0c84e..3509424 100644 --- a/lib/pki/pkcs12.ts +++ b/lib/pki/pkcs12.ts @@ -21,36 +21,18 @@ namespace trusted.pki { * @memberOf Pkcs12 */ public static load(filename: string): Pkcs12 { - let p12: Pkcs12 = new Pkcs12(); + const p12: Pkcs12 = new Pkcs12(); p12.handle.load(filename); return p12; } /** * Creates an instance of Pkcs12. - * - * - * @memberOf Pkcs12 - */ - constructor(); - - /** - * Creates an instance of Pkcs12. - * - * @param {native.PKI.Pkcs12} handle - * - * @memberOf Pkcs12 - */ - constructor(handle: native.PKI.Pkcs12); - - /** - * Creates an instance of Pkcs12. - * - * @param {*} [param] + * @param {native.PKI.Pkcs12} [param] * * @memberOf Pkcs12 */ - constructor(param?: any) { + constructor(param?: native.PKI.Pkcs12) { super(); if (param instanceof native.PKI.Pkcs12) { this.handle = param; @@ -92,7 +74,7 @@ namespace trusted.pki { * @memberOf Pkcs12 */ public ca(password: string): CertificateCollection { - let caCerts: CertificateCollection = new CertificateCollection(this.handle.getCACertificates(password)); + const caCerts: CertificateCollection = new CertificateCollection(this.handle.getCACertificates(password)); return caCerts; } @@ -131,7 +113,7 @@ namespace trusted.pki { * @memberOf Pkcs12 */ public create(cert: Certificate, key: Key, ca: CertificateCollection, password: string, name: string): Pkcs12 { - let p12: Pkcs12 = new Pkcs12(); + const p12: Pkcs12 = new Pkcs12(); p12.handle = this.handle.create(cert.handle, key.handle, ca ? ca.handle : undefined, password, name); return p12; } diff --git a/lib/pki/revocation.ts b/lib/pki/revocation.ts index c0aeb0a..5270239 100644 --- a/lib/pki/revocation.ts +++ b/lib/pki/revocation.ts @@ -17,20 +17,20 @@ namespace trusted.pki { * @param {string} path Path for save in local system * @param {Function} done callback function */ - function download(url: string, path: string, done: Function): void { + function download(url: string, path: string, done: (err: Error, url?: string, path?: string) => void): void { "use strict"; - let sendReq: any = request.get(url); + const sendReq: any = request.get(url); - sendReq.on("response", function (response) { + sendReq.on("response", function(response) { switch (response.statusCode) { case 200: - let stream = fs.createWriteStream(path); + const stream = fs.createWriteStream(path); - response.on("data", function (chunk) { + response.on("data", function(chunk) { stream.write(chunk); - }).on("end", function () { - stream.on("close", function () { + }).on("end", function() { + stream.on("close", function() { done(null, url, path); }); stream.end(); @@ -42,7 +42,7 @@ namespace trusted.pki { } }); - sendReq.on("error", function (err) { + sendReq.on("error", function(err) { fs.unlink(path); done(err.message); }); @@ -77,7 +77,7 @@ namespace trusted.pki { * @memberOf Revocation */ public getCrlLocal(cert: Certificate, store: pkistore.PkiStore): any { - let res = this.handle.getCrlLocal(cert.handle, store.handle); + const res = this.handle.getCrlLocal(cert.handle, store.handle); if (res) { return Crl.wrap(res); } @@ -117,13 +117,13 @@ namespace trusted.pki { * * @memberOf Revocation */ - public downloadCRL(distPoints: string[], pathForSave: string, done: Function): void { - let crl = new Crl(); + public downloadCRL(distPoints: string[], pathForSave: string, done: (err: Error, crl: Crl) => void): void { + const crl = new Crl(); let returnPath; try { - async.forEachOf(distPoints, function (value, key, callback) { - download(value, pathForSave + key, function (err, url, goodPath) { + async.forEachOf(distPoints, function(value, key, callback) { + download(value, pathForSave + key, function(err, url, goodPath) { if (err) { return callback(err); } else { @@ -131,7 +131,7 @@ namespace trusted.pki { callback(); } }); - }, function (err) { + }, function(err) { if (err) { done(err.message, null); } else { diff --git a/lib/pki/revoked.ts b/lib/pki/revoked.ts index 064f70d..8ee7a4c 100644 --- a/lib/pki/revoked.ts +++ b/lib/pki/revoked.ts @@ -13,29 +13,11 @@ namespace trusted.pki { export class Revoked extends BaseObject { /** * Creates an instance of Revoked. - * - * - * @memberOf Revoked - */ - constructor(); - - /** - * Creates an instance of Revoked. - * - * @param {native.PKI.Revoked} handle - * - * @memberOf Revoked - */ - constructor(handle: native.PKI.Revoked); - - /** - * Creates an instance of Revoked. - * - * @param {*} [param] + * @param {native.PKI.Revoked} [param] * * @memberOf Revoked */ - constructor(param?: any) { + constructor(param?: native.PKI.Revoked) { super(); if (param instanceof native.PKI.Revoked) { this.handle = param; @@ -85,7 +67,7 @@ namespace trusted.pki { * @memberOf Revoked */ public duplicate(): Revoked { - let rv: Revoked = new Revoked(); + const rv: Revoked = new Revoked(); rv.handle = this.handle.duplicate(); return rv; } diff --git a/lib/pki/revokeds.ts b/lib/pki/revokeds.ts index 84e3af4..4ea5d64 100644 --- a/lib/pki/revokeds.ts +++ b/lib/pki/revokeds.ts @@ -14,29 +14,11 @@ namespace trusted.pki { export class RevokedCollection extends BaseObject implements core.ICollectionWrite { /** * Creates an instance of RevokedCollection. - * - * @param {native.PKI.RevokedCollection} handle - * - * @memberOf RevokedCollection - */ - constructor(handle: native.PKI.RevokedCollection); - - /** - * Creates an instance of RevokedCollection. - * - * - * @memberOf RevokedCollection - */ - constructor(); - - /** - * Creates an instance of RevokedCollection. - * - * @param {*} [param] + * @param {native.PKI.RevokedCollection} [param] * * @memberOf RevokedCollection */ - constructor(param?: any) { + constructor(param?: native.PKI.RevokedCollection) { super(); if (param instanceof native.PKI.RevokedCollection) { this.handle = param; diff --git a/lib/pkistore/cashjson.ts b/lib/pkistore/cashjson.ts index a838d42..0d10b8f 100644 --- a/lib/pkistore/cashjson.ts +++ b/lib/pkistore/cashjson.ts @@ -41,53 +41,53 @@ namespace trusted.pkistore { * @memberOf CashJson */ public import(items: native.PKISTORE.IPkiItem[]): void { - for (let i: number = 0; i < items.length; i++) { - let pkiItem: PkiItem = new PkiItem(); + for (const item of items) { + const pkiItem: PkiItem = new PkiItem(); - pkiItem.format = items[i].format; - pkiItem.type = items[i].type; - pkiItem.category = items[i].category; - pkiItem.provider = items[i].provider; - pkiItem.uri = items[i].uri; - pkiItem.hash = items[i].hash.toLocaleLowerCase(); - if (items[i].subjectName) { - pkiItem.subjectName = items[i].subjectName; + pkiItem.format = item.format; + pkiItem.type = item.type; + pkiItem.category = item.category; + pkiItem.provider = item.provider; + pkiItem.uri = item.uri; + pkiItem.hash = item.hash.toLocaleLowerCase(); + if (item.subjectName) { + pkiItem.subjectName = item.subjectName; } - if (items[i].subjectFriendlyName) { - pkiItem.subjectFriendlyName = items[i].subjectFriendlyName; + if (item.subjectFriendlyName) { + pkiItem.subjectFriendlyName = item.subjectFriendlyName; } - if (items[i].issuerName) { - pkiItem.issuerName = items[i].issuerName; + if (item.issuerName) { + pkiItem.issuerName = item.issuerName; } - if (items[i].issuerFriendlyName) { - pkiItem.issuerFriendlyName = items[i].issuerFriendlyName; + if (item.issuerFriendlyName) { + pkiItem.issuerFriendlyName = item.issuerFriendlyName; } - if (items[i].serial) { - pkiItem.serial = items[i].serial; + if (item.serial) { + pkiItem.serial = item.serial; } - if (items[i].notBefore) { - pkiItem.notBefore = items[i].notBefore; + if (item.notBefore) { + pkiItem.notBefore = item.notBefore; } - if (items[i].notAfter) { - pkiItem.notAfter = items[i].notAfter; + if (item.notAfter) { + pkiItem.notAfter = item.notAfter; } - if (items[i].lastUpdate) { - pkiItem.lastUpdate = items[i].lastUpdate; + if (item.lastUpdate) { + pkiItem.lastUpdate = item.lastUpdate; } - if (items[i].nextUpdate) { - pkiItem.nextUpdate = items[i].nextUpdate; + if (item.nextUpdate) { + pkiItem.nextUpdate = item.nextUpdate; } - if (items[i].key) { - pkiItem.key = items[i].key; + if (item.key) { + pkiItem.key = item.key; } - if (items[i].encrypted) { - pkiItem.keyEnc = items[i].encrypted; + if (item.encrypted) { + pkiItem.keyEnc = item.encrypted; } - if (items[i].organizationName) { - pkiItem.organizationName = items[i].organizationName; + if (item.organizationName) { + pkiItem.organizationName = item.organizationName; } - if (items[i].signatureAlgorithm) { - pkiItem.signatureAlgorithm = items[i].signatureAlgorithm; + if (item.signatureAlgorithm) { + pkiItem.signatureAlgorithm = item.signatureAlgorithm; } this.handle.import(pkiItem.handle); diff --git a/lib/pkistore/pkistore.ts b/lib/pkistore/pkistore.ts index 2c5af2b..f16cff9 100644 --- a/lib/pkistore/pkistore.ts +++ b/lib/pkistore/pkistore.ts @@ -156,36 +156,19 @@ namespace trusted.pkistore { /** * Creates an instance of PkiStore. - * - * @param {native.PKISTORE.PkiStore} handle - * - * @memberOf PkiStore - */ - constructor(handle: native.PKISTORE.PkiStore); - - /** - * Creates an instance of PkiStore. - * - * @param {string} folder Path for create store + * @param {(native.PKISTORE.PkiStore | string)} param * * @memberOf PkiStore */ - constructor(folder: string); - - /** - * Creates an instance of PkiStore. - * - * @param {*} param - * - * @memberOf PkiStore - */ - constructor(param: any) { + constructor(param: native.PKISTORE.PkiStore | string) { super(); - if (param instanceof native.PKISTORE.PkiStore) { - this.handle = param; - } else { + if (typeof (param) === "string") { this.handle = new native.PKISTORE.PkiStore(param); this.cashJson = new CashJson(param); + } else if (param instanceof native.PKISTORE.PkiStore) { + this.handle = param; + } else { + throw new TypeError("PkiStore::constructor: Wrong input param"); } } @@ -279,7 +262,7 @@ namespace trusted.pkistore { * @memberOf PkiStore */ public find(ifilter?: native.PKISTORE.IFilter): native.PKISTORE.IPkiItem[] { - let filter: Filter = new Filter(); + const filter: Filter = new Filter(); if (!ifilter) { return this.handle.find(filter.handle); @@ -339,7 +322,7 @@ namespace trusted.pkistore { * @memberOf PkiStore */ public findKey(ifilter: native.PKISTORE.IFilter): native.PKISTORE.IPkiItem { - let filter: Filter = new Filter(); + const filter: Filter = new Filter(); if (ifilter.type) { for (let i: number = 0; i < ifilter.type.length; i++) { @@ -395,7 +378,7 @@ namespace trusted.pkistore { * @memberOf PkiStore */ public getItem(item: native.PKISTORE.IPkiItem): any { - let pkiItem: PkiItem = new PkiItem(); + const pkiItem: PkiItem = new PkiItem(); pkiItem.format = item.format; pkiItem.type = item.type; diff --git a/lib/utils/cerber.ts b/lib/utils/cerber.ts index 59e20ec..060eed2 100644 --- a/lib/utils/cerber.ts +++ b/lib/utils/cerber.ts @@ -101,7 +101,7 @@ namespace trusted.utils { */ constructor() { super(); - }; + } /** * Sign package @@ -121,9 +121,8 @@ namespace trusted.utils { let sd: cms.SignedData; let signer: cms.Signer; - let policies; - let str = JSON.stringify(modules, null, 2); + const str = JSON.stringify(modules, null, 2); fs2.writeFileSync(cerberLockPath, str); sd = new trusted.cms.SignedData(); @@ -155,7 +154,7 @@ namespace trusted.utils { const buffer = fs2.readFileSync(cerberLockPath, "utf8"); const ccerber = JSON.parse(buffer); - let res: IVerifyStatus = {signature: false, difModules: []}; + const res: IVerifyStatus = {signature: false, difModules: []}; let cms: cms.SignedData; @@ -208,7 +207,7 @@ namespace trusted.utils { let certs: pki.CertificateCollection; let signerCert: pki.Certificate; let cms: cms.SignedData; - let res = []; + const res = []; cms = new trusted.cms.SignedData(); cms.load(cerberLockPath + ".sig", trusted.DataFormat.PEM); @@ -221,7 +220,7 @@ namespace trusted.utils { signerId = signer.signerId; for (let j = 0; j < certs.length; j++) { - let tmpCert: trusted.pki.Certificate = certs.items(j); + const tmpCert: trusted.pki.Certificate = certs.items(j); if ((tmpCert.issuerName === signerId.issuerName) && (tmpCert.serialNumber === signerId.serialNumber)) { signer.certificate = tmpCert; @@ -253,9 +252,9 @@ namespace trusted.utils { */ private rehash(dir: string, relative?: string): string[] { let modules = []; - let filenames = fs2.readdirSync(dir); + const filenames = fs2.readdirSync(dir); - let filteredFiles = filenames.filter(function(e) { + const filteredFiles = filenames.filter(function(e) { if (DEFAULT_IGNORE.indexOf(e) < 0) { return true; } @@ -272,8 +271,8 @@ namespace trusted.utils { modules = modules.concat(this.rehash(loc, rel)); } else { if (stat.isFile()) { - let buffer = fs2.readFileSync(loc, "binary"); - let hash = crypto2.createHash("sha1").update(buffer).digest("hex"); + const buffer = fs2.readFileSync(loc, "binary"); + const hash = crypto2.createHash("sha1").update(buffer).digest("hex"); if (OS_TYPE === "Windows_NT") { rel = rel.replace(/\\/g, "/"); diff --git a/lib/utils/jwt.ts b/lib/utils/jwt.ts index dc35c28..3ee886e 100644 --- a/lib/utils/jwt.ts +++ b/lib/utils/jwt.ts @@ -20,7 +20,7 @@ namespace trusted.utils { * @memberOf Jwt */ public static checkLicense(data?: string): boolean { - let jwt = new native.UTILS.Jwt(); + const jwt = new native.UTILS.Jwt(); return (data ? jwt.checkLicense(data) : jwt.checkLicense()); } @@ -33,7 +33,7 @@ namespace trusted.utils { constructor() { super(); this.handle = new native.UTILS.Jwt(); - }; + } /** * Verify jwt license file diff --git a/lib/utils/logger.ts b/lib/utils/logger.ts index 908492c..dbea662 100644 --- a/lib/utils/logger.ts +++ b/lib/utils/logger.ts @@ -23,7 +23,7 @@ namespace trusted.utils { * @memberOf Logger */ public static start(filename: string, level: LoggerLevel = DEFAULT_LOGGER_LEVEL): Logger { - let logger = new Logger(); + const logger = new Logger(); logger.handle.start(filename, level); return logger; } @@ -36,7 +36,7 @@ namespace trusted.utils { constructor() { super(); this.handle = new native.UTILS.Logger(); - }; + } /** * Start write log to a file diff --git a/package.json b/package.json index 1e512cd..23f5105 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "lintES": "./node_modules/.bin/eslint test", "lintTS": "./node_modules/.bin/tslint lib/**/*.ts", "build": "node-gyp configure && node-gyp build && tsc", - "coverage": "nyc npm test", + "coverage": "nyc node_modules/.bin/mocha test", "coveralls": "nyc report --reporter=text-lcov | coveralls" }, "keywords": [