pax_global_header00006660000000000000000000000064141403115160014506gustar00rootroot0000000000000052 comment=b6986f6fddfbdcd25c20d82a0411f466b0886524 node-asn1-0.2.6/000077500000000000000000000000001414031151600133005ustar00rootroot00000000000000node-asn1-0.2.6/.eslintrc000066400000000000000000000005151414031151600151250ustar00rootroot00000000000000{ "plugins": [ "joyent" ], "extends": [ "eslint:recommended", "plugin:joyent/style", "plugin:joyent/lint" ], "parserOptions": { "ecmaVersion": 5, "sourceType": "script", "ecmaFeatures": { } }, "env": { "node": true }, "rules": { } } node-asn1-0.2.6/.gitignore000066400000000000000000000000451414031151600152670ustar00rootroot00000000000000/build /coverage /node_modules *.log node-asn1-0.2.6/.gitmodules000066400000000000000000000001351414031151600154540ustar00rootroot00000000000000[submodule "deps/jsstyle"] path = deps/jsstyle url = https://github.com/joyent/jsstyle.git node-asn1-0.2.6/.npmignore000066400000000000000000000001661414031151600153020ustar00rootroot00000000000000*.log /Makefile /deps /test /tools /.gitmodules /.npmignore /.eslintrc /.travis.yml /CONTRIBUTING.md /build /coverage node-asn1-0.2.6/CONTRIBUTING.md000066400000000000000000000007221414031151600155320ustar00rootroot00000000000000# Contributing This repository uses GitHub pull requests for code review. See the [Joyent Engineering Guidelines](https://github.com/joyent/eng/blob/master/docs/index.md) for general best practices expected in this repository. Contributions should be "make prepush" clean. The "prepush" target runs the "check" target, which will check for linting and style errors. If you're changing something non-trivial or user-facing, you may want to submit an issue first. node-asn1-0.2.6/Jenkinsfile000066400000000000000000000032631414031151600154700ustar00rootroot00000000000000@Library('jenkins-joylib@v1.0.8') _ pipeline { agent none options { buildDiscarder(logRotator(numToKeepStr: '45')) timestamps() } stages { stage('top') { parallel { stage('v4-zone') { agent { label joyCommonLabels(image_ver: '15.4.1') } tools { nodejs 'sdcnode-v4-zone' } stages { stage('check') { steps{ sh('make check') } } stage('test') { steps{ sh('make test') } } } } stage('v6-zone64') { agent { label joyCommonLabels(image_ver: '18.4.0') } tools { nodejs 'sdcnode-v6-zone64' } stages { stage('check') { steps{ sh('make check') } } stage('test') { steps{ sh('make test') } } } } } } } post { always { joySlackNotifications() } } } node-asn1-0.2.6/LICENSE000066400000000000000000000020641414031151600143070ustar00rootroot00000000000000Copyright (c) 2011 Mark Cavage, All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE node-asn1-0.2.6/Makefile000066400000000000000000000020121414031151600147330ustar00rootroot00000000000000# # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright 2019, Joyent, Inc. # # # node-asn1 Makefile # # # Tools # ISTANBUL := node_modules/.bin/istanbul FAUCET := node_modules/.bin/faucet NODE := node NPM := npm # # Files # JS_FILES := $(shell find lib test -name '*.js') JSSTYLE_FILES = $(JS_FILES) JSSTYLE_FLAGS = -f tools/jsstyle.conf ESLINT = ./node_modules/.bin/eslint ESLINT_FILES = $(JS_FILES) include ./tools/mk/Makefile.defs include ./tools/mk/Makefile.smf.defs # # Repo-specific targets # .PHONY: all all: $(TAPE) $(NPM) rebuild $(ISTANBUL): | $(NPM_EXEC) $(NPM) install $(FAUCET): | $(NPM_EXEC) $(NPM) install CLEAN_FILES += ./node_modules/ .PHONY: test test: $(ISTANBUL) $(FAUCET) $(ISTANBUL) cover --print none test/run.js | $(FAUCET) include ./tools/mk/Makefile.deps include ./tools/mk/Makefile.smf.targ include ./tools/mk/Makefile.targ node-asn1-0.2.6/README.md000066400000000000000000000022611414031151600145600ustar00rootroot00000000000000node-asn1 is a library for encoding and decoding ASN.1 datatypes in pure JS. Currently BER encoding is supported; at some point I'll likely have to do DER. ## Usage Mostly, if you're *actually* needing to read and write ASN.1, you probably don't need this readme to explain what and why. If you have no idea what ASN.1 is, see this: ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc The source is pretty much self-explanatory, and has read/write methods for the common types out there. ### Decoding The following reads an ASN.1 sequence with a boolean. var Ber = require('asn1').Ber; var reader = new Ber.Reader(Buffer.from([0x30, 0x03, 0x01, 0x01, 0xff])); reader.readSequence(); console.log('Sequence len: ' + reader.length); if (reader.peek() === Ber.Boolean) console.log(reader.readBoolean()); ### Encoding The following generates the same payload as above. var Ber = require('asn1').Ber; var writer = new Ber.Writer(); writer.startSequence(); writer.writeBoolean(true); writer.endSequence(); console.log(writer.buffer); ## Installation npm install asn1 ## License MIT. ## Bugs See . node-asn1-0.2.6/deps/000077500000000000000000000000001414031151600142335ustar00rootroot00000000000000node-asn1-0.2.6/deps/jsstyle/000077500000000000000000000000001414031151600157305ustar00rootroot00000000000000node-asn1-0.2.6/lib/000077500000000000000000000000001414031151600140465ustar00rootroot00000000000000node-asn1-0.2.6/lib/ber/000077500000000000000000000000001414031151600146165ustar00rootroot00000000000000node-asn1-0.2.6/lib/ber/errors.js000066400000000000000000000003601414031151600164670ustar00rootroot00000000000000// Copyright 2011 Mark Cavage All rights reserved. module.exports = { newInvalidAsn1Error: function (msg) { var e = new Error(); e.name = 'InvalidAsn1Error'; e.message = msg || ''; return e; } }; node-asn1-0.2.6/lib/ber/index.js000066400000000000000000000007251414031151600162670ustar00rootroot00000000000000// Copyright 2011 Mark Cavage All rights reserved. var errors = require('./errors'); var types = require('./types'); var Reader = require('./reader'); var Writer = require('./writer'); // --- Exports module.exports = { Reader: Reader, Writer: Writer }; for (var t in types) { if (types.hasOwnProperty(t)) module.exports[t] = types[t]; } for (var e in errors) { if (errors.hasOwnProperty(e)) module.exports[e] = errors[e]; } node-asn1-0.2.6/lib/ber/reader.js000066400000000000000000000130221414031151600164140ustar00rootroot00000000000000// Copyright 2011 Mark Cavage All rights reserved. var assert = require('assert'); var Buffer = require('safer-buffer').Buffer; var ASN1 = require('./types'); var errors = require('./errors'); // --- Globals var newInvalidAsn1Error = errors.newInvalidAsn1Error; // --- API function Reader(data) { if (!data || !Buffer.isBuffer(data)) throw new TypeError('data must be a node Buffer'); this._buf = data; this._size = data.length; // These hold the "current" state this._len = 0; this._offset = 0; } Object.defineProperty(Reader.prototype, 'length', { enumerable: true, get: function () { return (this._len); } }); Object.defineProperty(Reader.prototype, 'offset', { enumerable: true, get: function () { return (this._offset); } }); Object.defineProperty(Reader.prototype, 'remain', { get: function () { return (this._size - this._offset); } }); Object.defineProperty(Reader.prototype, 'buffer', { get: function () { return (this._buf.slice(this._offset)); } }); /** * Reads a single byte and advances offset; you can pass in `true` to make this * a "peek" operation (i.e., get the byte, but don't advance the offset). * * @param {Boolean} peek true means don't move offset. * @return {Number} the next byte, null if not enough data. */ Reader.prototype.readByte = function (peek) { if (this._size - this._offset < 1) return null; var b = this._buf[this._offset] & 0xff; if (!peek) this._offset += 1; return b; }; Reader.prototype.peek = function () { return this.readByte(true); }; /** * Reads a (potentially) variable length off the BER buffer. This call is * not really meant to be called directly, as callers have to manipulate * the internal buffer afterwards. * * As a result of this call, you can call `Reader.length`, until the * next thing called that does a readLength. * * @return {Number} the amount of offset to advance the buffer. * @throws {InvalidAsn1Error} on bad ASN.1 */ Reader.prototype.readLength = function (offset) { if (offset === undefined) offset = this._offset; if (offset >= this._size) return null; var lenB = this._buf[offset++] & 0xff; if (lenB === null) return null; if ((lenB & 0x80) === 0x80) { lenB &= 0x7f; if (lenB === 0) throw newInvalidAsn1Error('Indefinite length not supported'); if (lenB > 4) throw newInvalidAsn1Error('encoding too long'); if (this._size - offset < lenB) return null; this._len = 0; for (var i = 0; i < lenB; i++) this._len = (this._len << 8) + (this._buf[offset++] & 0xff); } else { // Wasn't a variable length this._len = lenB; } return offset; }; /** * Parses the next sequence in this BER buffer. * * To get the length of the sequence, call `Reader.length`. * * @return {Number} the sequence's tag. */ Reader.prototype.readSequence = function (tag) { var seq = this.peek(); if (seq === null) return null; if (tag !== undefined && tag !== seq) throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + ': got 0x' + seq.toString(16)); var o = this.readLength(this._offset + 1); // stored in `length` if (o === null) return null; this._offset = o; return seq; }; Reader.prototype.readInt = function () { return this._readTag(ASN1.Integer); }; Reader.prototype.readBoolean = function () { return (this._readTag(ASN1.Boolean) === 0 ? false : true); }; Reader.prototype.readEnumeration = function () { return this._readTag(ASN1.Enumeration); }; Reader.prototype.readString = function (tag, retbuf) { if (!tag) tag = ASN1.OctetString; var b = this.peek(); if (b === null) return null; if (b !== tag) throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + ': got 0x' + b.toString(16)); var o = this.readLength(this._offset + 1); // stored in `length` if (o === null) return null; if (this.length > this._size - o) return null; this._offset = o; if (this.length === 0) return retbuf ? Buffer.alloc(0) : ''; var str = this._buf.slice(this._offset, this._offset + this.length); this._offset += this.length; return retbuf ? str : str.toString('utf8'); }; Reader.prototype.readOID = function (tag) { if (!tag) tag = ASN1.OID; var b = this.readString(tag, true); if (b === null) return null; var values = []; var value = 0; for (var i = 0; i < b.length; i++) { var byte = b[i] & 0xff; value <<= 7; value += byte & 0x7f; if ((byte & 0x80) === 0) { values.push(value); value = 0; } } value = values.shift(); values.unshift(value % 40); values.unshift((value / 40) >> 0); return values.join('.'); }; Reader.prototype._readTag = function (tag) { assert.ok(tag !== undefined); var b = this.peek(); if (b === null) return null; if (b !== tag) throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) + ': got 0x' + b.toString(16)); var o = this.readLength(this._offset + 1); // stored in `length` if (o === null) return null; if (this.length > 4) throw newInvalidAsn1Error('Integer too long: ' + this.length); if (this.length > this._size - o) return null; this._offset = o; var fb = this._buf[this._offset]; var value = 0; for (var i = 0; i < this.length; i++) { value <<= 8; value |= (this._buf[this._offset++] & 0xff); } if ((fb & 0x80) === 0x80 && i !== 4) value -= (1 << (i * 8)); return value >> 0; }; // --- Exported API module.exports = Reader; node-asn1-0.2.6/lib/ber/types.js000066400000000000000000000011761414031151600163250ustar00rootroot00000000000000// Copyright 2011 Mark Cavage All rights reserved. module.exports = { EOC: 0, Boolean: 1, Integer: 2, BitString: 3, OctetString: 4, Null: 5, OID: 6, ObjectDescriptor: 7, External: 8, Real: 9, // float Enumeration: 10, PDV: 11, Utf8String: 12, RelativeOID: 13, Sequence: 16, Set: 17, NumericString: 18, PrintableString: 19, T61String: 20, VideotexString: 21, IA5String: 22, UTCTime: 23, GeneralizedTime: 24, GraphicString: 25, VisibleString: 26, GeneralString: 28, UniversalString: 29, CharacterString: 30, BMPString: 31, Constructor: 32, Context: 128 }; node-asn1-0.2.6/lib/ber/writer.js000066400000000000000000000167621414031151600165040ustar00rootroot00000000000000// Copyright 2011 Mark Cavage All rights reserved. var assert = require('assert'); var Buffer = require('safer-buffer').Buffer; var ASN1 = require('./types'); var errors = require('./errors'); // --- Globals var newInvalidAsn1Error = errors.newInvalidAsn1Error; var DEFAULT_OPTS = { size: 1024, growthFactor: 8 }; // --- Helpers function merge(from, to) { assert.ok(from); assert.equal(typeof (from), 'object'); assert.ok(to); assert.equal(typeof (to), 'object'); var keys = Object.getOwnPropertyNames(from); keys.forEach(function (key) { if (to[key]) return; var value = Object.getOwnPropertyDescriptor(from, key); Object.defineProperty(to, key, value); }); return to; } // --- API function Writer(options) { options = merge(DEFAULT_OPTS, options || {}); this._buf = Buffer.alloc(options.size || 1024); this._size = this._buf.length; this._offset = 0; this._options = options; // A list of offsets in the buffer where we need to insert // sequence tag/len pairs. this._seq = []; } Object.defineProperty(Writer.prototype, 'buffer', { get: function () { if (this._seq.length) throw newInvalidAsn1Error(this._seq.length + ' unended sequence(s)'); return (this._buf.slice(0, this._offset)); } }); Writer.prototype.writeByte = function (b) { if (typeof (b) !== 'number') throw new TypeError('argument must be a Number'); this._ensure(1); this._buf[this._offset++] = b; }; Writer.prototype.writeInt = function (i, tag) { if (typeof (i) !== 'number') throw new TypeError('argument must be a Number'); if (typeof (tag) !== 'number') tag = ASN1.Integer; var sz = 4; while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000 >> 0)) && (sz > 1)) { sz--; i <<= 8; } if (sz > 4) throw newInvalidAsn1Error('BER ints cannot be > 0xffffffff'); this._ensure(2 + sz); this._buf[this._offset++] = tag; this._buf[this._offset++] = sz; while (sz-- > 0) { this._buf[this._offset++] = ((i & 0xff000000) >>> 24); i <<= 8; } }; Writer.prototype.writeNull = function () { this.writeByte(ASN1.Null); this.writeByte(0x00); }; Writer.prototype.writeEnumeration = function (i, tag) { if (typeof (i) !== 'number') throw new TypeError('argument must be a Number'); if (typeof (tag) !== 'number') tag = ASN1.Enumeration; return this.writeInt(i, tag); }; Writer.prototype.writeBoolean = function (b, tag) { if (typeof (b) !== 'boolean') throw new TypeError('argument must be a Boolean'); if (typeof (tag) !== 'number') tag = ASN1.Boolean; this._ensure(3); this._buf[this._offset++] = tag; this._buf[this._offset++] = 0x01; this._buf[this._offset++] = b ? 0xff : 0x00; }; Writer.prototype.writeString = function (s, tag) { if (typeof (s) !== 'string') throw new TypeError('argument must be a string (was: ' + typeof (s) + ')'); if (typeof (tag) !== 'number') tag = ASN1.OctetString; var len = Buffer.byteLength(s); this.writeByte(tag); this.writeLength(len); if (len) { this._ensure(len); this._buf.write(s, this._offset); this._offset += len; } }; Writer.prototype.writeBuffer = function (buf, tag) { if (typeof (tag) !== 'number') throw new TypeError('tag must be a number'); if (!Buffer.isBuffer(buf)) throw new TypeError('argument must be a buffer'); this.writeByte(tag); this.writeLength(buf.length); this._ensure(buf.length); buf.copy(this._buf, this._offset, 0, buf.length); this._offset += buf.length; }; Writer.prototype.writeStringArray = function (strings) { if ((!strings instanceof Array)) throw new TypeError('argument must be an Array[String]'); var self = this; strings.forEach(function (s) { self.writeString(s); }); }; // This is really to solve DER cases, but whatever for now Writer.prototype.writeOID = function (s, tag) { if (typeof (s) !== 'string') throw new TypeError('argument must be a string'); if (typeof (tag) !== 'number') tag = ASN1.OID; if (!/^([0-9]+\.){3,}[0-9]+$/.test(s)) throw new Error('argument is not a valid OID string'); function encodeOctet(bytes, octet) { if (octet < 128) { bytes.push(octet); } else if (octet < 16384) { bytes.push((octet >>> 7) | 0x80); bytes.push(octet & 0x7F); } else if (octet < 2097152) { bytes.push((octet >>> 14) | 0x80); bytes.push(((octet >>> 7) | 0x80) & 0xFF); bytes.push(octet & 0x7F); } else if (octet < 268435456) { bytes.push((octet >>> 21) | 0x80); bytes.push(((octet >>> 14) | 0x80) & 0xFF); bytes.push(((octet >>> 7) | 0x80) & 0xFF); bytes.push(octet & 0x7F); } else { bytes.push(((octet >>> 28) | 0x80) & 0xFF); bytes.push(((octet >>> 21) | 0x80) & 0xFF); bytes.push(((octet >>> 14) | 0x80) & 0xFF); bytes.push(((octet >>> 7) | 0x80) & 0xFF); bytes.push(octet & 0x7F); } } var tmp = s.split('.'); var bytes = []; bytes.push(parseInt(tmp[0], 10) * 40 + parseInt(tmp[1], 10)); tmp.slice(2).forEach(function (b) { encodeOctet(bytes, parseInt(b, 10)); }); var self = this; this._ensure(2 + bytes.length); this.writeByte(tag); this.writeLength(bytes.length); bytes.forEach(function (b) { self.writeByte(b); }); }; Writer.prototype.writeLength = function (len) { if (typeof (len) !== 'number') throw new TypeError('argument must be a Number'); this._ensure(4); if (len <= 0x7f) { this._buf[this._offset++] = len; } else if (len <= 0xff) { this._buf[this._offset++] = 0x81; this._buf[this._offset++] = len; } else if (len <= 0xffff) { this._buf[this._offset++] = 0x82; this._buf[this._offset++] = len >> 8; this._buf[this._offset++] = len; } else if (len <= 0xffffff) { this._buf[this._offset++] = 0x83; this._buf[this._offset++] = len >> 16; this._buf[this._offset++] = len >> 8; this._buf[this._offset++] = len; } else { throw newInvalidAsn1Error('Length too long (> 4 bytes)'); } }; Writer.prototype.startSequence = function (tag) { if (typeof (tag) !== 'number') tag = ASN1.Sequence | ASN1.Constructor; this.writeByte(tag); this._seq.push(this._offset); this._ensure(3); this._offset += 3; }; Writer.prototype.endSequence = function () { var seq = this._seq.pop(); var start = seq + 3; var len = this._offset - start; if (len <= 0x7f) { this._shift(start, len, -2); this._buf[seq] = len; } else if (len <= 0xff) { this._shift(start, len, -1); this._buf[seq] = 0x81; this._buf[seq + 1] = len; } else if (len <= 0xffff) { this._buf[seq] = 0x82; this._buf[seq + 1] = len >> 8; this._buf[seq + 2] = len; } else if (len <= 0xffffff) { this._shift(start, len, 1); this._buf[seq] = 0x83; this._buf[seq + 1] = len >> 16; this._buf[seq + 2] = len >> 8; this._buf[seq + 3] = len; } else { throw newInvalidAsn1Error('Sequence too long'); } }; Writer.prototype._shift = function (start, len, shift) { assert.ok(start !== undefined); assert.ok(len !== undefined); assert.ok(shift); this._buf.copy(this._buf, start + shift, start, start + len); this._offset += shift; }; Writer.prototype._ensure = function (len) { assert.ok(len); if (this._size - this._offset < len) { var sz = this._size * this._options.growthFactor; if (sz - this._offset < len) sz += len; var buf = Buffer.alloc(sz); this._buf.copy(buf, 0, 0, this._offset); this._buf = buf; this._size = sz; } }; // --- Exported API module.exports = Writer; node-asn1-0.2.6/lib/index.js000066400000000000000000000005001414031151600155060ustar00rootroot00000000000000// Copyright 2011 Mark Cavage All rights reserved. // If you have no idea what ASN.1 or BER is, see this: // ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc var Ber = require('./ber/index'); // --- Exported API module.exports = { Ber: Ber, BerReader: Ber.Reader, BerWriter: Ber.Writer }; node-asn1-0.2.6/package.json000066400000000000000000000014161414031151600155700ustar00rootroot00000000000000{ "author": "Joyent (joyent.com)", "contributors": [ "Mark Cavage ", "David Gwynne ", "Yunong Xiao ", "Alex Wilson " ], "name": "asn1", "description": "Contains parsers and serializers for ASN.1 (currently BER only)", "version": "0.2.6", "repository": { "type": "git", "url": "https://github.com/joyent/node-asn1.git" }, "main": "lib/index.js", "dependencies": { "safer-buffer": "~2.1.0" }, "devDependencies": { "istanbul": "^0.3.6", "faucet": "0.0.1", "tape": "^3.5.0", "eslint": "2.13.1", "eslint-plugin-joyent": "~1.3.0" }, "scripts": { "test": "./node_modules/.bin/tape ./test/ber/*.test.js" }, "license": "MIT" } node-asn1-0.2.6/test/000077500000000000000000000000001414031151600142575ustar00rootroot00000000000000node-asn1-0.2.6/test/ber/000077500000000000000000000000001414031151600150275ustar00rootroot00000000000000node-asn1-0.2.6/test/ber/reader.test.js000066400000000000000000000133141414031151600176070ustar00rootroot00000000000000// Copyright 2011 Mark Cavage All rights reserved. var test = require('tape'); var Buffer = require('safer-buffer').Buffer; // --- Globals var BerReader; // --- Tests test('load library', function (t) { BerReader = require('../../lib/index').BerReader; t.ok(BerReader); try { var reader = new BerReader(); t.equal(reader, null, 'reader'); t.fail('Should have thrown'); } catch (e) { t.ok(e instanceof TypeError, 'Should have been a type error'); } t.end(); }); test('read byte', function (t) { var reader = new BerReader(Buffer.from([0xde])); t.ok(reader); t.equal(reader.readByte(), 0xde, 'wrong value'); t.end(); }); test('read 1 byte int', function (t) { var reader = new BerReader(Buffer.from([0x02, 0x01, 0x03])); t.ok(reader); t.equal(reader.readInt(), 0x03, 'wrong value'); t.equal(reader.length, 0x01, 'wrong length'); t.end(); }); test('read 2 byte int', function (t) { var reader = new BerReader(Buffer.from([0x02, 0x02, 0x7e, 0xde])); t.ok(reader); t.equal(reader.readInt(), 0x7ede, 'wrong value'); t.equal(reader.length, 0x02, 'wrong length'); t.end(); }); test('read 3 byte int', function (t) { var reader = new BerReader(Buffer.from([0x02, 0x03, 0x7e, 0xde, 0x03])); t.ok(reader); t.equal(reader.readInt(), 0x7ede03, 'wrong value'); t.equal(reader.length, 0x03, 'wrong length'); t.end(); }); test('read 4 byte int', function (t) { var reader = new BerReader(Buffer.from([0x02, 0x04, 0x7e, 0xde, 0x03, 0x01])); t.ok(reader); t.equal(reader.readInt(), 0x7ede0301, 'wrong value'); t.equal(reader.length, 0x04, 'wrong length'); t.end(); }); test('read 1 byte negative int', function (t) { var reader = new BerReader(Buffer.from([0x02, 0x01, 0xdc])); t.ok(reader); t.equal(reader.readInt(), -36, 'wrong value'); t.equal(reader.length, 0x01, 'wrong length'); t.end(); }); test('read 2 byte negative int', function (t) { var reader = new BerReader(Buffer.from([0x02, 0x02, 0xc0, 0x4e])); t.ok(reader); t.equal(reader.readInt(), -16306, 'wrong value'); t.equal(reader.length, 0x02, 'wrong length'); t.end(); }); test('read 3 byte negative int', function (t) { var reader = new BerReader(Buffer.from([0x02, 0x03, 0xff, 0x00, 0x19])); t.ok(reader); t.equal(reader.readInt(), -65511, 'wrong value'); t.equal(reader.length, 0x03, 'wrong length'); t.end(); }); test('read 4 byte negative int', function (t) { var reader = new BerReader(Buffer.from([0x02, 0x04, 0x91, 0x7c, 0x22, 0x1f])); t.ok(reader); t.equal(reader.readInt(), -1854135777, 'wrong value'); t.equal(reader.length, 0x04, 'wrong length'); t.end(); }); test('read boolean true', function (t) { var reader = new BerReader(Buffer.from([0x01, 0x01, 0xff])); t.ok(reader); t.equal(reader.readBoolean(), true, 'wrong value'); t.equal(reader.length, 0x01, 'wrong length'); t.end(); }); test('read boolean false', function (t) { var reader = new BerReader(Buffer.from([0x01, 0x01, 0x00])); t.ok(reader); t.equal(reader.readBoolean(), false, 'wrong value'); t.equal(reader.length, 0x01, 'wrong length'); t.end(); }); test('read enumeration', function (t) { var reader = new BerReader(Buffer.from([0x0a, 0x01, 0x20])); t.ok(reader); t.equal(reader.readEnumeration(), 0x20, 'wrong value'); t.equal(reader.length, 0x01, 'wrong length'); t.end(); }); test('read string', function (t) { var dn = 'cn=foo,ou=unit,o=test'; var buf = Buffer.alloc(dn.length + 2); buf[0] = 0x04; buf[1] = Buffer.byteLength(dn); buf.write(dn, 2); var reader = new BerReader(buf); t.ok(reader); t.equal(reader.readString(), dn, 'wrong value'); t.equal(reader.length, dn.length, 'wrong length'); t.end(); }); test('read sequence', function (t) { var reader = new BerReader(Buffer.from([0x30, 0x03, 0x01, 0x01, 0xff])); t.ok(reader); t.equal(reader.readSequence(), 0x30, 'wrong value'); t.equal(reader.length, 0x03, 'wrong length'); t.equal(reader.readBoolean(), true, 'wrong value'); t.equal(reader.length, 0x01, 'wrong length'); t.end(); }); test('anonymous LDAPv3 bind', function (t) { var BIND = Buffer.alloc(14); BIND[0] = 0x30; // Sequence BIND[1] = 12; // len BIND[2] = 0x02; // ASN.1 Integer BIND[3] = 1; // len BIND[4] = 0x04; // msgid (make up 4) BIND[5] = 0x60; // Bind Request BIND[6] = 7; // len BIND[7] = 0x02; // ASN.1 Integer BIND[8] = 1; // len BIND[9] = 0x03; // v3 BIND[10] = 0x04; // String (bind dn) BIND[11] = 0; // len BIND[12] = 0x80; // ContextSpecific (choice) BIND[13] = 0; // simple bind // Start testing ^^ var ber = new BerReader(BIND); t.equal(ber.readSequence(), 48, 'Not an ASN.1 Sequence'); t.equal(ber.length, 12, 'Message length should be 12'); t.equal(ber.readInt(), 4, 'Message id should have been 4'); t.equal(ber.readSequence(), 96, 'Bind Request should have been 96'); t.equal(ber.length, 7, 'Bind length should have been 7'); t.equal(ber.readInt(), 3, 'LDAP version should have been 3'); t.equal(ber.readString(), '', 'Bind DN should have been empty'); t.equal(ber.length, 0, 'string length should have been 0'); t.equal(ber.readByte(), 0x80, 'Should have been ContextSpecific (choice)'); t.equal(ber.readByte(), 0, 'Should have been simple bind'); t.equal(null, ber.readByte(), 'Should be out of data'); t.end(); }); test('long string', function (t) { var buf = Buffer.alloc(256); var s = '2;649;CN=Red Hat CS 71GA Demo,O=Red Hat CS 71GA Demo,C=US;' + 'CN=RHCS Agent - admin01,UID=admin01,O=redhat,C=US [1] This is ' + 'Teena Vradmin\'s description.'; buf[0] = 0x04; buf[1] = 0x81; buf[2] = 0x94; buf.write(s, 3); var ber = new BerReader(buf.slice(0, 3 + s.length)); t.equal(ber.readString(), s); t.end(); }); node-asn1-0.2.6/test/ber/writer.test.js000066400000000000000000000224031414031151600176600ustar00rootroot00000000000000// Copyright 2011 Mark Cavage All rights reserved. var test = require('tape'); var Buffer = require('safer-buffer').Buffer; // --- Globals var BerWriter; // --- Tests test('load library', function (t) { BerWriter = require('../../lib/index').BerWriter; t.ok(BerWriter); t.ok(new BerWriter()); t.end(); }); test('write byte', function (t) { var writer = new BerWriter(); writer.writeByte(0xC2); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 1, 'Wrong length'); t.equal(ber[0], 0xC2, 'value wrong'); t.end(); }); test('write 1 byte int', function (t) { var writer = new BerWriter(); writer.writeInt(0x7f); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 3, 'Wrong length for an int: ' + ber.length); t.equal(ber[0], 0x02, 'ASN.1 tag wrong (2) -> ' + ber[0]); t.equal(ber[1], 0x01, 'length wrong(1) -> ' + ber[1]); t.equal(ber[2], 0x7f, 'value wrong(3) -> ' + ber[2]); t.end(); }); test('write 2 byte int', function (t) { var writer = new BerWriter(); writer.writeInt(0x7ffe); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 4, 'Wrong length for an int'); t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); t.equal(ber[1], 0x02, 'length wrong'); t.equal(ber[2], 0x7f, 'value wrong (byte 1)'); t.equal(ber[3], 0xfe, 'value wrong (byte 2)'); t.end(); }); test('write 3 byte int', function (t) { var writer = new BerWriter(); writer.writeInt(0x7ffffe); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 5, 'Wrong length for an int'); t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); t.equal(ber[1], 0x03, 'length wrong'); t.equal(ber[2], 0x7f, 'value wrong (byte 1)'); t.equal(ber[3], 0xff, 'value wrong (byte 2)'); t.equal(ber[4], 0xfe, 'value wrong (byte 3)'); t.end(); }); test('write 4 byte int', function (t) { var writer = new BerWriter(); writer.writeInt(0x7ffffffe); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 6, 'Wrong length for an int'); t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); t.equal(ber[1], 0x04, 'length wrong'); t.equal(ber[2], 0x7f, 'value wrong (byte 1)'); t.equal(ber[3], 0xff, 'value wrong (byte 2)'); t.equal(ber[4], 0xff, 'value wrong (byte 3)'); t.equal(ber[5], 0xfe, 'value wrong (byte 4)'); t.end(); }); test('write 1 byte negative int', function (t) { var writer = new BerWriter(); writer.writeInt(-128); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 3, 'Wrong length for an int'); t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); t.equal(ber[1], 0x01, 'length wrong'); t.equal(ber[2], 0x80, 'value wrong (byte 1)'); t.end(); }); test('write 2 byte negative int', function (t) { var writer = new BerWriter(); writer.writeInt(-22400); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 4, 'Wrong length for an int'); t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); t.equal(ber[1], 0x02, 'length wrong'); t.equal(ber[2], 0xa8, 'value wrong (byte 1)'); t.equal(ber[3], 0x80, 'value wrong (byte 2)'); t.end(); }); test('write 3 byte negative int', function (t) { var writer = new BerWriter(); writer.writeInt(-481653); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 5, 'Wrong length for an int'); t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); t.equal(ber[1], 0x03, 'length wrong'); t.equal(ber[2], 0xf8, 'value wrong (byte 1)'); t.equal(ber[3], 0xa6, 'value wrong (byte 2)'); t.equal(ber[4], 0x8b, 'value wrong (byte 3)'); t.end(); }); test('write 4 byte negative int', function (t) { var writer = new BerWriter(); writer.writeInt(-1522904131); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 6, 'Wrong length for an int'); t.equal(ber[0], 0x02, 'ASN.1 tag wrong'); t.equal(ber[1], 0x04, 'length wrong'); t.equal(ber[2], 0xa5, 'value wrong (byte 1)'); t.equal(ber[3], 0x3a, 'value wrong (byte 2)'); t.equal(ber[4], 0x53, 'value wrong (byte 3)'); t.equal(ber[5], 0xbd, 'value wrong (byte 4)'); t.end(); }); test('write boolean', function (t) { var writer = new BerWriter(); writer.writeBoolean(true); writer.writeBoolean(false); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 6, 'Wrong length'); t.equal(ber[0], 0x01, 'tag wrong'); t.equal(ber[1], 0x01, 'length wrong'); t.equal(ber[2], 0xff, 'value wrong'); t.equal(ber[3], 0x01, 'tag wrong'); t.equal(ber[4], 0x01, 'length wrong'); t.equal(ber[5], 0x00, 'value wrong'); t.end(); }); test('write string', function (t) { var writer = new BerWriter(); writer.writeString('hello world'); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 13, 'wrong length'); t.equal(ber[0], 0x04, 'wrong tag'); t.equal(ber[1], 11, 'wrong length'); t.equal(ber.slice(2).toString('utf8'), 'hello world', 'wrong value'); t.end(); }); test('write buffer', function (t) { var writer = new BerWriter(); // write some stuff to start with writer.writeString('hello world'); var ber = writer.buffer; var buf = Buffer.from([0x04, 0x0b, 0x30, 0x09, 0x02, 0x01, 0x0f, 0x01, 0x01, 0xff, 0x01, 0x01, 0xff]); writer.writeBuffer(buf.slice(2, buf.length), 0x04); ber = writer.buffer; t.ok(ber); t.equal(ber.length, 26, 'wrong length'); t.equal(ber[0], 0x04, 'wrong tag'); t.equal(ber[1], 11, 'wrong length'); t.equal(ber.slice(2, 13).toString('utf8'), 'hello world', 'wrong value'); t.equal(ber[13], buf[0], 'wrong tag'); t.equal(ber[14], buf[1], 'wrong length'); for (var i = 13, j = 0; i < ber.length && j < buf.length; i++, j++) { t.equal(ber[i], buf[j], 'buffer contents not identical'); } t.end(); }); test('write string array', function (t) { var writer = new BerWriter(); writer.writeStringArray(['hello world', 'fubar!']); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 21, 'wrong length'); t.equal(ber[0], 0x04, 'wrong tag'); t.equal(ber[1], 11, 'wrong length'); t.equal(ber.slice(2, 13).toString('utf8'), 'hello world', 'wrong value'); t.equal(ber[13], 0x04, 'wrong tag'); t.equal(ber[14], 6, 'wrong length'); t.equal(ber.slice(15).toString('utf8'), 'fubar!', 'wrong value'); t.end(); }); test('resize internal buffer', function (t) { var writer = new BerWriter({size: 2}); writer.writeString('hello world'); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 13, 'wrong length'); t.equal(ber[0], 0x04, 'wrong tag'); t.equal(ber[1], 11, 'wrong length'); t.equal(ber.slice(2).toString('utf8'), 'hello world', 'wrong value'); t.end(); }); test('sequence', function (t) { var writer = new BerWriter({size: 25}); writer.startSequence(); writer.writeString('hello world'); writer.endSequence(); var ber = writer.buffer; t.ok(ber); console.log(ber); t.equal(ber.length, 15, 'wrong length'); t.equal(ber[0], 0x30, 'wrong tag'); t.equal(ber[1], 13, 'wrong length'); t.equal(ber[2], 0x04, 'wrong tag'); t.equal(ber[3], 11, 'wrong length'); t.equal(ber.slice(4).toString('utf8'), 'hello world', 'wrong value'); t.end(); }); test('nested sequence', function (t) { var writer = new BerWriter({size: 25}); writer.startSequence(); writer.writeString('hello world'); writer.startSequence(); writer.writeString('hello world'); writer.endSequence(); writer.endSequence(); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 30, 'wrong length'); t.equal(ber[0], 0x30, 'wrong tag'); t.equal(ber[1], 28, 'wrong length'); t.equal(ber[2], 0x04, 'wrong tag'); t.equal(ber[3], 11, 'wrong length'); t.equal(ber.slice(4, 15).toString('utf8'), 'hello world', 'wrong value'); t.equal(ber[15], 0x30, 'wrong tag'); t.equal(ber[16], 13, 'wrong length'); t.equal(ber[17], 0x04, 'wrong tag'); t.equal(ber[18], 11, 'wrong length'); t.equal(ber.slice(19, 30).toString('utf8'), 'hello world', 'wrong value'); t.end(); }); test('LDAP bind message', function (t) { var dn = 'cn=foo,ou=unit,o=test'; var writer = new BerWriter(); writer.startSequence(); writer.writeInt(3); // msgid = 3 writer.startSequence(0x60); // ldap bind writer.writeInt(3); // ldap v3 writer.writeString(dn); writer.writeByte(0x80); writer.writeByte(0x00); writer.endSequence(); writer.endSequence(); var ber = writer.buffer; t.ok(ber); t.equal(ber.length, 35, 'wrong length (buffer)'); t.equal(ber[0], 0x30, 'wrong tag'); t.equal(ber[1], 33, 'wrong length'); t.equal(ber[2], 0x02, 'wrong tag'); t.equal(ber[3], 1, 'wrong length'); t.equal(ber[4], 0x03, 'wrong value'); t.equal(ber[5], 0x60, 'wrong tag'); t.equal(ber[6], 28, 'wrong length'); t.equal(ber[7], 0x02, 'wrong tag'); t.equal(ber[8], 1, 'wrong length'); t.equal(ber[9], 0x03, 'wrong value'); t.equal(ber[10], 0x04, 'wrong tag'); t.equal(ber[11], dn.length, 'wrong length'); t.equal(ber.slice(12, 33).toString('utf8'), dn, 'wrong value'); t.equal(ber[33], 0x80, 'wrong tag'); t.equal(ber[34], 0x00, 'wrong len'); t.end(); }); test('Write OID', function (t) { var oid = '1.2.840.113549.1.1.1'; var writer = new BerWriter(); writer.writeOID(oid); var ber = writer.buffer; t.ok(ber); console.log(require('util').inspect(ber)); console.log(require('util').inspect(Buffer.from([0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01]))); t.end(); }); node-asn1-0.2.6/test/run.js000066400000000000000000000005451414031151600154250ustar00rootroot00000000000000/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* * Copyright (c) 2018, Joyent, Inc. */ 'use strict'; // --- Run All Tests require('./ber/reader.test.js'); require('./ber/writer.test.js'); node-asn1-0.2.6/tools/000077500000000000000000000000001414031151600144405ustar00rootroot00000000000000node-asn1-0.2.6/tools/jsstyle.conf000066400000000000000000000004611414031151600170050ustar00rootroot00000000000000# # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2018, Joyent, Inc. # indent=2 doxygen unparenthesized-return=0 strict-indent=true node-asn1-0.2.6/tools/mk/000077500000000000000000000000001414031151600150475ustar00rootroot00000000000000node-asn1-0.2.6/tools/mk/Makefile.defs000066400000000000000000000071031414031151600174300ustar00rootroot00000000000000# # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2018, Joyent, Inc. # # # Makefile.defs: common defines. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # # This makefile defines some useful defines. Include it at the top of # your Makefile. # # Definitions in this Makefile: # # TOP The absolute path to the project directory. The top dir. # BRANCH The current git branch. # TIMESTAMP The timestamp for the build. This can be set via # the TIMESTAMP envvar (used by MG-based builds). # STAMP A build stamp to use in built package names. # # MAKE_STAMPS_DIR The directory in which make stamp files are to be # created. See comments below on expensive targets. # # CACHE_DIR A directory tree in which temporary files may be # collected by download, tarball extraction, etc. This # directory is completely removed by "make distclean". # Files in this directory are not intended to be shipped. # TOP := $(shell pwd) # # Mountain Gorilla-spec'd versioning. # See "Package Versioning" in MG's README.md: # # # Need GNU awk for multi-char arg to "-F". _AWK := $(shell (which gawk >/dev/null && echo gawk) \ || (which nawk >/dev/null && echo nawk) \ || echo awk) BRANCH := $(shell git symbolic-ref HEAD | $(_AWK) -F/ '{print $$3}') ifeq ($(TIMESTAMP),) TIMESTAMP := $(shell date -u "+%Y%m%dT%H%M%SZ") endif _GITDESCRIBE := g$(shell git describe --all --long --dirty | $(_AWK) -F'-g' '{print $$NF}') STAMP := $(BRANCH)-$(TIMESTAMP)-$(_GITDESCRIBE) # node-gyp will print build info useful for debugging with V=1 export V=1 CACHE_DIR ?= cache DISTCLEAN_FILES += $(CACHE_DIR) # # EXPENSIVE TARGETS AND MAKE STAMP FILES # # Targets which are expensive to run and lack a single file that marks # completion are difficult to track with make; e.g., "npm install". One # solution to this problem is to create "stamp" files with symbolic names which # are created as the final step in a complex make rule in order to mark # completion. # # In order to make these more uniform, and easier to target with "make clean", # we will attempt to store them under a single directory. Note that these # files are never targets for shipping in build artefacts. # # Stamp-backed targets come in several parts. First, a macro should be defined # which names a file in the MAKE_STAMPS_DIR directory. Then, a target which # creates this stamp file must be provided. The recipe for this target should # use MAKE_STAMP_REMOVE and MAKE_STAMP_CREATE to perform the appropriate stamp # management. # # For example: # # --- Makefile.*.defs: # # $(STAMP_EXPENSIVE_RESULT) := $(MAKE_STAMPS_DIR)/expensive-result # # --- Makefile.*.targ: # # $(STAMP_EXPENSIVE_RESULT): input/file another/input/file # $(MAKE_STAMP_REMOVE) # rm -rf output_tree/ # <--- ensure a clean slate # expensive_program -o output_tree/ $^ # $(MAKE_STAMP_CREATE) # # NOTE: Every stamp file is exposed as an implicit "stamp-$STAMP_NAME" target. # The example above could be built manually by invoking: # # make stamp-expensive-result # MAKE_STAMPS_DIR ?= make_stamps CLEAN_FILES += $(MAKE_STAMPS_DIR) MAKE_STAMP_REMOVE = mkdir -p $(@D); rm -f $(@) MAKE_STAMP_CREATE = mkdir -p $(@D); touch $(@) node-asn1-0.2.6/tools/mk/Makefile.deps000066400000000000000000000051201414031151600174370ustar00rootroot00000000000000# -*- mode: makefile -*- # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2017, Joyent, Inc. # # # Makefile.deps: Makefile for including common tools as dependencies # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # # This file is separate from Makefile.targ so that teams can choose # independently whether to use the common targets in Makefile.targ and the # common tools here. # # # javascriptlint # JSL_EXEC ?= deps/javascriptlint/build/install/jsl JSL ?= $(JSL_EXEC) $(JSL_EXEC): | deps/javascriptlint/.git cd deps/javascriptlint && make install distclean:: if [[ -f deps/javascriptlint/Makefile ]]; then \ cd deps/javascriptlint && make clean; \ fi # # jsstyle # JSSTYLE_EXEC ?= deps/jsstyle/jsstyle JSSTYLE ?= $(JSSTYLE_EXEC) $(JSSTYLE_EXEC): | deps/jsstyle/.git # # eslint # ESLINT_EXEC ?= node_modules/.bin/eslint ifdef NODE ESLINT := $(NODE) $(ESLINT_EXEC) else ESLINT ?= $(ESLINT_EXEC) endif # Install eslint. # # The install of specific modules is to allow running "make check" # without having to do a complete install of all npm dependencies. # # NPM_EXEC will be defined if either of "Makefile.{node,node_prebuilt}.defs" # is included. ifdef NPM $(ESLINT_EXEC): package.json | $(NPM_EXEC) ESLINT_VER=$$($(NODE) -e 'console.log(require("./package.json").devDependencies["eslint"] || "")') && \ ESLINT_JOY_VER=$$($(NODE) -e 'console.log(require("./package.json").devDependencies["eslint-plugin-joyent"] || "")') && \ [[ -n $$ESLINT_VER && -n $$ESLINT_JOY_VER ]] && \ $(NPM) install --no-save eslint@$$ESLINT_VER eslint-plugin-joyent@$$ESLINT_JOY_VER && \ touch $(ESLINT_EXEC) else $(ESLINT_EXEC): package.json ESLINT_VER=$$(node -e 'console.log(require("./package.json").devDependencies["eslint"] || "")') && \ ESLINT_JOY_VER=$$(node -e 'console.log(require("./package.json").devDependencies["eslint-plugin-joyent"] || "")') && \ [[ -n $$ESLINT_VER && -n $$ESLINT_JOY_VER ]] && \ npm install --no-save eslint@$$ESLINT_VER eslint-plugin-joyent@$$ESLINT_JOY_VER && \ touch $(ESLINT_EXEC) endif # # restdown # RESTDOWN_EXEC ?= deps/restdown/bin/restdown RESTDOWN ?= python $(RESTDOWN_EXEC) $(RESTDOWN_EXEC): | deps/restdown/.git EXTRA_DOC_DEPS ?= node-asn1-0.2.6/tools/mk/Makefile.node.defs000066400000000000000000000104041414031151600203520ustar00rootroot00000000000000# # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2017, Joyent, Inc. # # # Makefile.node.defs: Makefile for building and bundling your own Node.js. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # # # This Makefile facilitates building and bundling your own copy of Node.js in # your repo. All it does is define variables for node, node-waf, and npm for # you to use elsewhere in your Makefile and rules to build these tools when # needed. # # To use this facility, include "Makefile.node.defs", use the variables as # described below to define targets, and then include "Makefile.node.targ". # # There are two use cases addressed here: # # (1) Invoking node, node-waf, or npm as part of the build process, as in "npm # install" and "node-waf configure build". To facilitate this, this # Makefile defines Make variables NODE, NODE_WAF, and NPM that you can use # to invoke these commands during the build process. You MUST NOT assume # that these variables just evaluate to the filenames themselves, as they # may have environment variable definitions and other things that prevent # you from using them directly as a filename. If you want that, see (2). # # Wherever you use one of these variables, you MUST include a dependency on # the corresponding *_EXEC variable as well, like so: # # node_modules/restify: deps/restify $(NPM_EXEC) # $(NPM) install deps/restify # # or better, use an order-only dependency to avoid spurious rebuilds: # # node_modules/restify: deps/restify | $(NPM_EXEC) # $(NPM) install deps/restify # # Otherwise, the underlying file will not get built. We don't # automatically build them as part of "all" because that approach is # brittle. # # (2) Specifying paths for invoking node, node-waf, or npm at RUNTIME, as in # specifying the path to node used for the start method of your service's # SMF manifest. For this, this Makefile defines variables NODE_EXEC, # NODE_WAF_EXEC, and NPM_EXEC, which represent the relative paths of these # files from the root of the workspace. You MUST NOT use these variables # to invoke these commands during the build process. See (1) instead. # # However, in order to work at runtime, you must build the tool as well. # That is, if you use NODE_EXEC to specify the path to node, you must # depend on NODE_EXEC somewhere. This usually happens anyway because you # usually need them during the build process too, but if you don't then # you need to explicitly add NODE_EXEC (or whichever) to your "all" # target. # # When including this Makefile, you MAY also specify: # # BUILD top-level directory for built binaries # (default: "build") # # NODE_INSTALL where node should install its built items # (default: "$BUILD/node") # # NODE_CONFIG_FLAGS extra flags to pass to Node's "configure" # (default: "--with-dtrace" on SmartOS; empty # otherwise.) # TOP ?= $(error You must include Makefile.defs before this makefile) BUILD ?= build NODE_INSTALL ?= $(BUILD)/node DISTCLEAN_FILES += $(NODE_INSTALL) NODE_CONFIG_FLAGS += --prefix=$(TOP)/$(NODE_INSTALL) ifeq ($(shell uname -s),SunOS) NODE_CONFIG_FLAGS += --with-dtrace \ --openssl-libpath=/opt/local/lib \ --openssl-includes=/opt/local/include endif NODE_EXEC = $(NODE_INSTALL)/bin/node NODE_WAF_EXEC = $(NODE_INSTALL)/bin/node-waf NPM_EXEC = $(NODE_INSTALL)/bin/npm # # These paths should be used during the build process to invoke Node and # Node-related build tools like NPM. All paths are fully qualified so that # they work regardless of the current working directory at the point of # invocation. # # Note that where PATH is overridden, the value chosen must cause execution of # "node" to find the same binary to which the NODE macro refers. # NODE := $(TOP)/$(NODE_EXEC) NODE_WAF := $(TOP)/$(NODE_WAF_EXEC) NPM := PATH=$(TOP)/$(NODE_INSTALL)/bin:$(PATH) $(NODE) $(TOP)/$(NPM_EXEC) node-asn1-0.2.6/tools/mk/Makefile.node.targ000066400000000000000000000026251414031151600203740ustar00rootroot00000000000000# -*- mode: makefile -*- # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2014, Joyent, Inc. # # # Makefile.node.targ: See Makefile.node.defs. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # ifneq ($(shell uname -s),SunOS) NODE_PREBUILT_VERSION ?= $(error You must define NODE_PREBUILT_VERSION to use Makefile.node.targ on non-SunOS) endif ifeq ($(shell uname -s),SunOS) $(NODE_EXEC) $(NPM_EXEC) $(NODE_WAF_EXEC): | deps/node/.git (cd deps/node; ./configure $(NODE_CONFIG_FLAGS) && $(MAKE) && $(MAKE) install) else $(NODE_EXEC) $(NPM_EXEC) $(NODE_WAF_EXEC): (mkdir -p $(BUILD) \ && cd $(BUILD) \ && [[ -d src-node ]] && (cd src-node && git checkout master && git pull) || git clone https://github.com/joyent/node.git src-node \ && cd src-node \ && git checkout $(NODE_PREBUILT_VERSION) \ && ./configure $(NODE_CONFIG_FLAGS) \ && $(MAKE) && $(MAKE) install) endif DISTCLEAN_FILES += $(NODE_INSTALL) $(BUILD)/src-node distclean:: -([[ ! -d deps/node ]] || (cd deps/node && $(MAKE) distclean)) node-asn1-0.2.6/tools/mk/Makefile.node_deps.defs000066400000000000000000000031151414031151600213660ustar00rootroot00000000000000# -*- mode: makefile -*- # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2014, Joyent, Inc. # # # Makefile.node_deps.defs: Makefile for including npm modules whose sources # reside inside the repo. This should NOT be used for modules in the npm # public repo or modules that could be specified with git SHAs. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # # # This Makefile takes as input the following make variable: # # REPO_MODULES List of relative paths to node modules (i.e., npm # packages) inside this repo. For example: # src/node-canative, where there's a binary npm package # in src/node-canative. # # Based on the above, this Makefile defines the following new variables: # # REPO_DEPS List of relative paths to the installed modules. For # example: "node_modules/canative". # # The accompanying Makefile.node_deps.targ defines a target that will install # each of REPO_MODULES into REPO_DEPS and remove REPO_DEPS with "make clean". # The top-level Makefile is responsible for depending on REPO_DEPS where # appropriate (usually the "deps" or "all" target). # REPO_DEPS = $(REPO_MODULES:src/node-%=node_modules/%) CLEAN_FILES += $(REPO_DEPS) node-asn1-0.2.6/tools/mk/Makefile.node_deps.targ000066400000000000000000000013751414031151600214100ustar00rootroot00000000000000# -*- mode: makefile -*- # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2014, Joyent, Inc. # # # Makefile.node_deps.targ: targets for Makefile.node_deps.defs. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # NPM_EXEC ?= $(error NPM_EXEC must be defined for Makefile.node_deps.targ) node_modules/%: src/node-% | $(NPM_EXEC) $(NPM) install $< node-asn1-0.2.6/tools/mk/Makefile.node_prebuilt.defs000066400000000000000000000144411414031151600222650ustar00rootroot00000000000000# # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2017, Joyent, Inc. # # # Makefile.node_prebuilt.defs: Makefile for including a prebuilt Node.js build. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # # # This Makefile facilitates downloading and bundling a prebuilt node.js # build (using the 'sdcnode' distro builds). This is an alternative to # the "Makefile.node.*" makefiles for *building* a node from source. # # Usage: # # - Define `NODE_PREBUILT_VERSION` in your Makefile to choose a node version. # E.g.: `NODE_PREBUILT_VERSION=v0.6.19`. See other optional variables # below. # - `include tools/mk/Makefile.node_prebuilt.defs` after this in your Makefile. # - `include tools/mk/Makefile.node_prebuilt.targ` near the end of your # Makefile. # - Have at least one of your Makefile targets depend on either `$(NODE_EXEC)` # or `$(NPM_EXEC)`. E.g.: # # node_modules/restify: deps/restify $(NPM_EXEC) # $(NPM) install deps/restify # # or better, use an order-only dependency to avoid spurious rebuilds: # # node_modules/restify: deps/restify | $(NPM_EXEC) # $(NPM) install deps/restify # # - Use `$(NPM)` or `$(NODE)` to use your node build. # - Include the "$(NODE_INSTALL)" tree in your release package. # # # When including this Makefile, you MUST also specify: # # NODE_PREBUILT_VERSION The node version in the prebuilt 'sdcnode' # package to use. Typically this is one of the # node version tags, e.g. "v0.6.18" but it # can be any commitish. # # When including this Makefile, you MAY also specify: # # NODE_PREBUILT_DIR The dir in which to find sdcnode builds. This # can either be a *local directory* or *a # URL* dir (with trailing '/') which serves # Apache/Nginx dir listing HTML. # (default: sdcnode master build dir on stuff) # # NODE_PREBUILT_TAG The 'sdcnode' project supports special # configuration builds of node, e.g. say a # build configured `--without-ssl`. These # special configurations are given a tag, e.g. # 'gz', that is used in the filename. Optionally # specify a tag name here. # (default: empty) # # NODE_PREBUILT_BRANCH Specify a particular branch of 'sdcnode' builds # from which to pull. Generally one should stick # with the default. # (default: master) # # NODE_PREBUILT_IMAGE If you have a zone image that differs from that # for an sdcnode build that you want to use (potential compat # issues be damned), then set this to the UUID of the sdcnode # build you want. See here for available build image uuids: # # # BUILD top-level directory for built binaries # (default: "build") # # NODE_INSTALL where node should install its built items # (default: "$BUILD/node") # # # Dev Notes: # # This works by getting "NODE_PREBUILT_NAME" from the provided "NODE_PREBUILT_*" # vars and the image version (via 'mdata-get sdc:image_uuid'). The image uuid is # included to ensure an exact match with the build machine. This name (e.g. # "v0.6.18-zone-$uuid") is used to find a matching "sdcnode-$name-*.tgz" build # in "NODE_PREBUILT_DIR" (either a local directory or a URL). That tarball is # downloaded and extracted into "NODE_INSTALL". # # The "*_EXEC" vars are set to named symlinks, e.g. # "build/prebuilt-node-v0.6.18-$uuid", so that a change of selected node # build (say the developer changes NODE_PREBUILT_VERSION) will recreate the # node install. # # See for details on 'sdcnode-*' # package naming. # TOP ?= $(error You must include Makefile.defs before this makefile) NODE_PREBUILT_VERSION ?= $(error NODE_PREBUILT_VERSION is not set.) BUILD ?= build NODE_INSTALL ?= $(BUILD)/node DISTCLEAN_FILES += $(NODE_INSTALL) \ $(BUILD)/prebuilt-node-* $(BUILD)/prebuilt-npm-* NODE_PREBUILT_BRANCH ?= master NODE_PREBUILT_IMAGE ?= $(shell pfexec mdata-get sdc:image_uuid) ifeq ($(NODE_PREBUILT_TAG),) NODE_PREBUILT_NAME := $(NODE_PREBUILT_VERSION)-$(NODE_PREBUILT_IMAGE) else NODE_PREBUILT_NAME := $(NODE_PREBUILT_VERSION)-$(NODE_PREBUILT_TAG)-$(NODE_PREBUILT_IMAGE) endif NODE_PREBUILT_PATTERN := sdcnode-$(NODE_PREBUILT_NAME)-$(NODE_PREBUILT_BRANCH)-.*\.tgz NODE_PREBUILT_DIR ?= https://download.joyent.com/pub/build/sdcnode/$(NODE_PREBUILT_IMAGE)/$(NODE_PREBUILT_BRANCH)-latest/sdcnode/ ifeq ($(shell echo $(NODE_PREBUILT_DIR) | cut -c 1-4),http) NODE_PREBUILT_BASE := $(shell curl -ksS --fail --connect-timeout 30 $(NODE_PREBUILT_DIR) | grep 'href=' | cut -d'"' -f2 | grep "^$(NODE_PREBUILT_PATTERN)$$" | sort | tail -1) ifneq ($(NODE_PREBUILT_BASE),) NODE_PREBUILT_TARBALL := $(NODE_PREBUILT_DIR)$(NODE_PREBUILT_BASE) endif else NODE_PREBUILT_BASE := $(shell ls -1 $(NODE_PREBUILT_DIR)/ | grep "^$(NODE_PREBUILT_PATTERN)$$" 2>/dev/null | sort | tail -1) ifneq ($(NODE_PREBUILT_BASE),) NODE_PREBUILT_TARBALL := $(NODE_PREBUILT_DIR)/$(NODE_PREBUILT_BASE) endif endif ifeq ($(NODE_PREBUILT_TARBALL),) NODE_PREBUILT_TARBALL = $(error NODE_PREBUILT_TARBALL is empty: no '$(NODE_PREBUILT_DIR)/$(NODE_PREBUILT_PATTERN)' found) endif # Prebuild-specific paths for the "*_EXEC" vars to ensure that # a prebuild change (e.g. if master Makefile's NODE_PREBUILT_VERSION # choice changes) causes a install of the new node. NODE_EXEC := $(BUILD)/prebuilt-node-$(NODE_PREBUILT_NAME) NODE_WAF_EXEC := $(BUILD)/prebuilt-node-waf-$(NODE_PREBUILT_NAME) NPM_EXEC := $(BUILD)/prebuilt-npm-$(NODE_PREBUILT_NAME) # # These paths should be used during the build process to invoke Node and # Node-related build tools like NPM. All paths are fully qualified so that # they work regardless of the current working directory at the point of # invocation. # # Note that where PATH is overridden, the value chosen must cause execution of # "node" to find the same binary to which the NODE macro refers. # NODE := $(TOP)/$(NODE_INSTALL)/bin/node NODE_WAF := $(TOP)/$(NODE_INSTALL)/bin/node-waf NPM := PATH=$(TOP)/$(NODE_INSTALL)/bin:$(PATH) $(NODE) $(TOP)/$(NODE_INSTALL)/bin/npm node-asn1-0.2.6/tools/mk/Makefile.node_prebuilt.targ000066400000000000000000000033131414031151600222750ustar00rootroot00000000000000# -*- mode: makefile -*- # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2014, Joyent, Inc. # # # Makefile.node_prebuilt.targ: Makefile for including a prebuilt Node.js # build. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. NODE_PREBUILT_TARBALL ?= $(error NODE_PREBUILT_TARBALL is not set: was Makefile.node_prebuilt.defs included?) # TODO: remove this limitation # Limitation: currently presuming that the NODE_INSTALL basename is # 'node' and that sdcnode tarballs have a 'node' top-level dir. $(NODE_EXEC) $(NPM_EXEC) $(NODE_WAF_EXEC): [[ $(shell basename $(NODE_INSTALL)) == "node" ]] \ || (echo "Limitation: 'basename NODE_INSTALL' is not 'node'" && exit 1) rm -rf $(NODE_INSTALL) \ $(BUILD)/prebuilt-node-* $(BUILD)/prebuilt-npm-* mkdir -p $(shell dirname $(NODE_INSTALL)) if [[ $(shell echo $(NODE_PREBUILT_TARBALL) | cut -c 1-4) == "http" ]]; then \ echo "Downloading '$(NODE_PREBUILT_BASE)'."; \ curl -ksS --fail --connect-timeout 30 -o $(shell dirname $(NODE_INSTALL))/$(NODE_PREBUILT_BASE) $(NODE_PREBUILT_TARBALL); \ (cd $(shell dirname $(NODE_INSTALL)) && $(TAR) xf $(NODE_PREBUILT_BASE)); \ else \ (cd $(shell dirname $(NODE_INSTALL)) && $(TAR) xf $(NODE_PREBUILT_TARBALL)); \ fi ln -s $(TOP)/$(NODE_INSTALL)/bin/node $(NODE_EXEC) ln -s $(TOP)/$(NODE_INSTALL)/bin/npm $(NPM_EXEC) node-asn1-0.2.6/tools/mk/Makefile.smf.defs000066400000000000000000000023621414031151600202160ustar00rootroot00000000000000# -*- mode: makefile -*- # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2014, Joyent, Inc. # # # Makefile.smf.defs: common targets for SMF manifests # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # # This Makefile uses the following definitions: # # SMF_MANIFESTS_IN Source files for SMF manifests. The following # substitutions will be made on these files: # # @@NODE@@ path to installed node # # It updates SMF_MANIFESTS with the set of files generated by SMF_MANIFESTS_IN. # It also updates the "check" target to check the XML syntax of all manifests, # generated or otherwise. # # To use this file, be sure to also include Makefile.smf.targ after defining # targets. # SED ?= sed SMF_DTD ?= tools/service_bundle.dtd.1 XMLLINT ?= xmllint --noout SMF_MANIFESTS += $(SMF_MANIFESTS_IN:%.in=%) CLEAN_FILES += $(SMF_MANIFESTS_IN:%.in=%) node-asn1-0.2.6/tools/mk/Makefile.smf.targ000066400000000000000000000015511414031151600202310ustar00rootroot00000000000000# -*- mode: makefile -*- # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2014, Joyent, Inc. # # # Makefile.smf.targ: see Makefile.smf.defs. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # .PHONY: check-manifests check-manifests: $(SMF_MANIFESTS:%=%.smfchk) %.smfchk: % $(XMLLINT) --path $(dir $(SMF_DTD)) --dtdvalid $(SMF_DTD) $^ check:: check-manifests $(SMF_MANIFESTS): %: %.in $(SED) -e 's#@@NODE@@#@@PREFIX@@/$(NODE_INSTALL)/bin/node#' $< > $@ node-asn1-0.2.6/tools/mk/Makefile.targ000066400000000000000000000242771414031151600174570ustar00rootroot00000000000000# # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # # Copyright (c) 2017, Joyent, Inc. # # # Makefile.targ: common targets. # # NOTE: This makefile comes from the "eng" repo. It's designed to be dropped # into other repos as-is without requiring any modifications. If you find # yourself changing this file, you should instead update the original copy in # eng.git and then update your repo to use the new version. # # This Makefile defines several useful targets and rules. You can use it by # including it from a Makefile that specifies some of the variables below. # # Targets defined in this Makefile: # # check Checks JavaScript files for lint and style # Checks bash scripts for syntax # Checks SMF manifests for validity against the SMF DTD # # clean Removes built files # # docs Builds restdown documentation in docs/ # # prepush Depends on "check" and "test" # # test Does nothing (you should override this) # # xref Generates cscope (source cross-reference index) # # For details on what these targets are supposed to do, see the Joyent # Engineering Guide. # # To make use of these targets, you'll need to set some of these variables. Any # variables left unset will simply not be used. # # BASH_FILES Bash scripts to check for syntax # (paths relative to top-level Makefile) # # CLEAN_FILES Files to remove as part of the "clean" target. Note # that files generated by targets in this Makefile are # automatically included in CLEAN_FILES. These include # restdown-generated HTML and JSON files. # # DOC_FILES Restdown (documentation source) files. These are # assumed to be contained in "docs/", and must NOT # contain the "docs/" prefix. # # JSL_CONF_NODE Specify JavaScriptLint configuration files # JSL_CONF_WEB (paths relative to top-level Makefile) # # Node.js and Web configuration files are separate # because you'll usually want different global variable # configurations. If no file is specified, none is given # to jsl, which causes it to use a default configuration, # which probably isn't what you want. # # JSL_FILES_NODE JavaScript files to check with Node config file. # JSL_FILES_WEB JavaScript files to check with Web config file. # # JSON_FILES JSON files to be validated # # JSSTYLE_FILES JavaScript files to be style-checked # # You can also override these variables: # # BASH Path to bash (default: "bash") # # CSCOPE_DIRS Directories to search for source files for the cscope # index. (default: ".") # # ESLINT Path to eslint (default: "eslint") # # ESLINT_FLAGS Additional flags to pass through to eslint # # JSL Path to JavaScriptLint (default: "jsl") # # JSL_FLAGS_NODE Additional flags to pass through to JSL # JSL_FLAGS_WEB # JSL_FLAGS # # JSON Path to json tool (default: "json") # # JSSTYLE Path to jsstyle (default: "jsstyle") # # JSSTYLE_FLAGS Additional flags to pass through to jsstyle # # RESTDOWN_EXT By default '.md' is required for DOC_FILES (see above). # If you want to use, say, '.restdown' instead, then set # 'RESTDOWN_EXT=.restdown' in your Makefile. # # # Defaults for the various tools we use. # BASH ?= bash BASHSTYLE ?= $(NODE) tools/bashstyle CP ?= cp CSCOPE ?= cscope CSCOPE_DIRS ?= . ESLINT ?= eslint JSL ?= jsl JSON ?= json JSSTYLE ?= jsstyle MKDIR ?= mkdir -p MV ?= mv RESTDOWN_FLAGS ?= RESTDOWN_EXT ?= .md RMTREE ?= rm -rf JSL_FLAGS ?= --nologo --nosummary ifeq ($(shell uname -s),SunOS) TAR ?= gtar else TAR ?= tar endif # # Defaults for other fixed values. # BUILD = build DISTCLEAN_FILES += $(BUILD) DOC_BUILD = $(BUILD)/docs/public # # Configure JSL_FLAGS_{NODE,WEB} based on JSL_CONF_{NODE,WEB}. # ifneq ($(origin JSL_CONF_NODE), undefined) JSL_FLAGS_NODE += --conf=$(JSL_CONF_NODE) endif ifneq ($(origin JSL_CONF_WEB), undefined) JSL_FLAGS_WEB += --conf=$(JSL_CONF_WEB) endif # # Targets. For descriptions on what these are supposed to do, see the # Joyent Engineering Guide. # # # Instruct make to keep around temporary files. We have rules below that # automatically update git submodules as needed, but they employ a deps/*/.git # temporary file. Without this directive, make tries to remove these .git # directories after the build has completed. # .SECONDARY: $($(wildcard deps/*):%=%/.git) # # This rule enables other rules that use files from a git submodule to have # those files depend on deps/module/.git and have "make" automatically check # out the submodule as needed. # deps/%/.git: git submodule update --init deps/$* # # These recipes make heavy use of dynamically-created phony targets. The parent # Makefile defines a list of input files like BASH_FILES. We then say that each # of these files depends on a fake target called filename.bashchk, and then we # define a pattern rule for those targets that runs bash in check-syntax-only # mode. This mechanism has the nice properties that if you specify zero files, # the rule becomes a noop (unlike a single rule to check all bash files, which # would invoke bash with zero files), and you can check individual files from # the command line with "make filename.bashchk". # .PHONY: check-bash check-bash: $(BASH_FILES:%=%.bashchk) $(BASH_FILES:%=%.bashstyle) %.bashchk: % $(BASH) -n $^ %.bashstyle: % $(BASHSTYLE) $^ .PHONY: check-json check-json: $(JSON_FILES:%=%.jsonchk) %.jsonchk: % $(JSON) --validate -f $^ # # The above approach can be slow when there are many files to check because it # requires that "make" invoke the check tool once for each file, rather than # passing in several files at once. For the JavaScript check targets, we define # a variable for the target itself *only if* the list of input files is # non-empty. This avoids invoking the tool if there are no files to check. # ESLINT_TARGET = $(if $(ESLINT_FILES), check-eslint) .PHONY: check-eslint check-eslint: $(ESLINT_EXEC) $(ESLINT) $(ESLINT_FLAGS) $(ESLINT_FILES) JSL_NODE_TARGET = $(if $(JSL_FILES_NODE), check-jsl-node) .PHONY: check-jsl-node check-jsl-node: $(JSL_EXEC) $(JSL) $(JSL_FLAGS) $(JSL_FLAGS_NODE) $(JSL_FILES_NODE) JSL_WEB_TARGET = $(if $(JSL_FILES_WEB), check-jsl-web) .PHONY: check-jsl-web check-jsl-web: $(JSL_EXEC) $(JSL) $(JSL_FLAGS) $(JSL_FLAGS_WEB) $(JSL_FILES_WEB) .PHONY: check-jsl check-jsl: $(JSL_NODE_TARGET) $(JSL_WEB_TARGET) JSSTYLE_TARGET = $(if $(JSSTYLE_FILES), check-jsstyle) .PHONY: check-jsstyle check-jsstyle: $(JSSTYLE_EXEC) $(JSSTYLE) $(JSSTYLE_FLAGS) $(JSSTYLE_FILES) .PHONY: check check:: $(ESLINT_TARGET) check-jsl check-json $(JSSTYLE_TARGET) check-bash @echo check ok .PHONY: clean clean:: -$(RMTREE) $(CLEAN_FILES) .PHONY: distclean distclean:: clean -$(RMTREE) $(DISTCLEAN_FILES) CSCOPE_FILES = cscope.in.out cscope.out cscope.po.out CLEAN_FILES += $(CSCOPE_FILES) .PHONY: xref xref: cscope.files $(CSCOPE) -bqR .PHONY: cscope.files cscope.files: find $(CSCOPE_DIRS) -name '*.c' -o -name '*.h' -o -name '*.cc' \ -o -name '*.js' -o -name '*.s' -o -name '*.cpp' > $@ # # The "docs" target is complicated because we do several things here: # # (1) Use restdown to build HTML and JSON files from each of DOC_FILES. # # (2) Copy these files into $(DOC_BUILD) (build/docs/public), which # functions as a complete copy of the documentation that could be # mirrored or served over HTTP. # # (3) Then copy any directories and media from docs/media into # $(DOC_BUILD)/media. This allows projects to include their own media, # including files that will override same-named files provided by # restdown. # # Step (3) is the surprisingly complex part: in order to do this, we need to # identify the subdirectories in docs/media, recreate them in # $(DOC_BUILD)/media, then do the same with the files. # DOC_MEDIA_DIRS := $(shell find docs/media -type d 2>/dev/null | grep -v "^docs/media$$") DOC_MEDIA_DIRS := $(DOC_MEDIA_DIRS:docs/media/%=%) DOC_MEDIA_DIRS_BUILD := $(DOC_MEDIA_DIRS:%=$(DOC_BUILD)/media/%) DOC_MEDIA_FILES := $(shell find docs/media -type f 2>/dev/null) DOC_MEDIA_FILES := $(DOC_MEDIA_FILES:docs/media/%=%) DOC_MEDIA_FILES_BUILD := $(DOC_MEDIA_FILES:%=$(DOC_BUILD)/media/%) # # Like the other targets, "docs" just depends on the final files we want to # create in $(DOC_BUILD), leveraging other targets and recipes to define how # to get there. # .PHONY: docs docs:: \ $(DOC_FILES:%$(RESTDOWN_EXT)=$(DOC_BUILD)/%.html) \ $(DOC_FILES:%$(RESTDOWN_EXT)=$(DOC_BUILD)/%.json) \ $(DOC_MEDIA_FILES_BUILD) # # We keep the intermediate files so that the next build can see whether the # files in DOC_BUILD are up to date. # .PRECIOUS: \ $(DOC_FILES:%$(RESTDOWN_EXT)=docs/%.html) \ $(DOC_FILES:%$(RESTDOWN_EXT)=docs/%json) # # We do clean those intermediate files, as well as all of DOC_BUILD. # CLEAN_FILES += \ $(DOC_BUILD) \ $(DOC_FILES:%$(RESTDOWN_EXT)=docs/%.html) \ $(DOC_FILES:%$(RESTDOWN_EXT)=docs/%.json) # # Before installing the files, we must make sure the directories exist. The | # syntax tells make that the dependency need only exist, not be up to date. # Otherwise, it might try to rebuild spuriously because the directory itself # appears out of date. # $(DOC_MEDIA_FILES_BUILD): | $(DOC_MEDIA_DIRS_BUILD) $(DOC_BUILD)/%: docs/% | $(DOC_BUILD) $(MKDIR) $(shell dirname $@) $(CP) $< $@ docs/%.json docs/%.html: docs/%$(RESTDOWN_EXT) | $(DOC_BUILD) $(RESTDOWN_EXEC) \ $(EXTRA_DOC_DEPS) $(RESTDOWN) $(RESTDOWN_FLAGS) -m $(DOC_BUILD) $< $(DOC_BUILD): $(MKDIR) $@ $(DOC_MEDIA_DIRS_BUILD): $(MKDIR) $@ # # The default "test" target does nothing. This should usually be overridden by # the parent Makefile. It's included here so we can define "prepush" without # requiring the repo to define "test". # .PHONY: test test: .PHONY: prepush prepush: check test # # This rule automatically exposes every "stamp" file as a target that can be # invoked manually as "stamp-$STAMP_NAME". For example, if a stamp has been # defined thus: # # STAMP_EXPENSIVE_RESULT := $(MAKE_STAMPS_DIR)/expensive-result # # ... this can be invoked manually as "make stamp-expensive-result". Note that # these phony targets are essentially just for interactive usage. Targets # should be specified to depend on the macro containing the stamp file name. # # See also the comments in "Makefile.defs". # stamp-%: $(MAKE_STAMPS_DIR)/% @: