Skip to content

Commit

Permalink
Fix Lint and Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
romainv42 authored and rviau42 committed May 7, 2021
1 parent 9bd796b commit 3ea742d
Show file tree
Hide file tree
Showing 113 changed files with 499 additions and 416 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ module.exports = {
],
"keyword-spacing": [
"error",
{ "after": false }
{ "overrides": {
"if": { "after": false },
"for": { "after": false },
"while": { "after": false },
"catch": { "after": false },
}}
]
}
};
2 changes: 1 addition & 1 deletion src/AccessDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class AccessDescription
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "accessMethod":
return "";
Expand Down
4 changes: 2 additions & 2 deletions src/Accuracy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Accuracy
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "seconds":
case "millis":
Expand All @@ -67,7 +67,7 @@ export default class Accuracy
*/
static compareWithDefault(memberName, memberValue)
{
switch(memberName)
switch (memberName)
{
case "seconds":
case "millis":
Expand Down
4 changes: 2 additions & 2 deletions src/AlgorithmIdentifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class AlgorithmIdentifier
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "algorithmId":
return "";
Expand All @@ -60,7 +60,7 @@ export default class AlgorithmIdentifier
*/
static compareWithDefault(memberName, memberValue)
{
switch(memberName)
switch (memberName)
{
case "algorithmId":
return (memberValue === "");
Expand Down
2 changes: 1 addition & 1 deletion src/AltName.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class AltName
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "altNames":
return [];
Expand Down
7 changes: 4 additions & 3 deletions src/Attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { getParametersValue, clearProps } from "pvutils";
/**
* Class from RFC2986
*/
export default class Attribute {
export default class Attribute
{
//**********************************************************************************
/**
* Constructor for Attribute class
Expand Down Expand Up @@ -38,7 +39,7 @@ export default class Attribute {
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "type":
return "";
Expand All @@ -56,7 +57,7 @@ export default class Attribute {
*/
static compareWithDefault(memberName, memberValue)
{
switch(memberName)
switch (memberName)
{
case "type":
return (memberValue === "");
Expand Down
8 changes: 4 additions & 4 deletions src/AttributeCertificateV1.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class AttCertValidityPeriod
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "notBeforeTime":
case "notAfterTime":
Expand Down Expand Up @@ -195,7 +195,7 @@ export class IssuerSerial
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "issuer":
return new GeneralNames();
Expand Down Expand Up @@ -420,7 +420,7 @@ export class AttributeCertificateInfoV1
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "version":
return 0;
Expand Down Expand Up @@ -745,7 +745,7 @@ export default class AttributeCertificateV1
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "acinfo":
return new AttributeCertificateInfoV1();
Expand Down
12 changes: 6 additions & 6 deletions src/AttributeCertificateV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ObjectDigestInfo
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "digestedObjectType":
return new asn1js.Enumerated();
Expand Down Expand Up @@ -254,7 +254,7 @@ export class V2Form
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "issuerName":
return new GeneralNames();
Expand Down Expand Up @@ -488,7 +488,7 @@ export class Holder
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "baseCertificateID":
return new IssuerSerial();
Expand Down Expand Up @@ -769,7 +769,7 @@ export class AttributeCertificateInfoV2
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "version":
return 1;
Expand Down Expand Up @@ -929,7 +929,7 @@ export class AttributeCertificateInfoV2
this.version = asn1.result.version.valueBlock.valueDec;
this.holder = new Holder({ schema: asn1.result.holder });

switch(asn1.result.issuer.idBlock.tagClass)
switch (asn1.result.issuer.idBlock.tagClass)
{
case 3: // V2Form
this.issuer = new V2Form({
Expand Down Expand Up @@ -1061,7 +1061,7 @@ export default class AttributeCertificateV2
*/
static defaultValues(memberName)
{
switch(memberName)
switch (memberName)
{
case "acinfo":
return new AttributeCertificateInfoV2();
Expand Down
72 changes: 45 additions & 27 deletions src/AttributeTypeAndValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import AttributeTypeDictionary from "./AttributeTypeDictionary";
/**
* Class from RFC5280
*/
export default class AttributeTypeAndValue {
export default class AttributeTypeAndValue
{
//**********************************************************************************
/**
* Constructor for AttributeTypeAndValue class
* @param {Object} [parameters={}]
* @param {Object} [parameters.schema] asn1js parsed value to initialize the class from
*/
constructor(parameters = {}) {
constructor(parameters = {})
{
//region Internal properties of the object
/**
* @type {string}
Expand All @@ -28,7 +30,7 @@ export default class AttributeTypeAndValue {
//endregion

//region If input argument array contains "schema" for this object
if ("schema" in parameters)
if("schema" in parameters)
this.fromSchema(parameters.schema);
//endregion
}
Expand All @@ -37,8 +39,10 @@ export default class AttributeTypeAndValue {
* Return default values for all class members
* @param {string} memberName String name for a class member
*/
static defaultValues(memberName) {
switch (memberName) {
static defaultValues(memberName)
{
switch (memberName)
{
case "type":
return "";
case "value":
Expand All @@ -65,7 +69,8 @@ export default class AttributeTypeAndValue {
* @param {Object} parameters Input parameters for the schema
* @returns {Object} asn1js schema object
*/
static schema(parameters = {}) {
static schema(parameters = {})
{
/**
* @type {Object}
* @property {string} [blockName] Name for entire block
Expand All @@ -83,15 +88,17 @@ export default class AttributeTypeAndValue {
}));
}
//**********************************************************************************
static blockName() {
static blockName()
{
return "AttributeTypeAndValue";
}
//**********************************************************************************
/**
* Convert parsed asn1js object into current class
* @param {!Object} schema
*/
fromSchema(schema) {
fromSchema(schema)
{
//region Clear input data first
clearProps(schema, [
"type",
Expand All @@ -110,7 +117,7 @@ export default class AttributeTypeAndValue {
})
);

if (asn1.verified === false)
if(asn1.verified === false)
throw new Error("Object's schema was not verified against input data for AttributeTypeAndValue");
//endregion

Expand All @@ -125,7 +132,8 @@ export default class AttributeTypeAndValue {
* Convert current object to asn1js object and set correct values
* @returns {Object} asn1js object
*/
toSchema() {
toSchema()
{
//region Construct and return new ASN.1 schema for this object
return (new asn1js.Sequence({
value: [
Expand All @@ -140,12 +148,13 @@ export default class AttributeTypeAndValue {
* Convertion for the class to JSON object
* @returns {Object}
*/
toJSON() {
toJSON()
{
const _object = {
type: this.type
};

if (Object.keys(this.value).length !== 0)
if(Object.keys(this.value).length !== 0)
_object.value = this.value.toJSON();
else
_object.value = this.value;
Expand All @@ -158,7 +167,8 @@ export default class AttributeTypeAndValue {
* @param {(AttributeTypeAndValue|ArrayBuffer)} compareTo The value compare to current
* @returns {boolean}
*/
isEqual(compareTo) {
isEqual(compareTo)
{
const stringBlockNames = [
asn1js.Utf8String.blockName(),
asn1js.BmpString.blockName(),
Expand All @@ -174,63 +184,71 @@ export default class AttributeTypeAndValue {
asn1js.CharacterString.blockName()
];

if (compareTo.constructor.blockName() === AttributeTypeAndValue.blockName()) {
if (this.type !== compareTo.type)
if(compareTo.constructor.blockName() === AttributeTypeAndValue.blockName())
{
if(this.type !== compareTo.type)
return false;

//region Check we do have both strings
let isString = [false, false];
const thisName = this.value.constructor.blockName();
for (const name of stringBlockNames) {
if (thisName === name) {
for(const name of stringBlockNames)
{
if(thisName === name)
{
isString[0] = true;
}
if (compareTo.value.constructor.blockName() === name) {
if(compareTo.value.constructor.blockName() === name)
{
isString[1] = true;
}
}
if (isString[0] ^ isString[1])
if(isString[0] ^ isString[1])
return false;

isString = (isString[0] && isString[1]);
//endregion

if (isString) {
if(isString)
{
const value1 = stringPrep(this.value.valueBlock.value);
const value2 = stringPrep(compareTo.value.valueBlock.value);

if (value1.localeCompare(value2) !== 0)
if(value1.localeCompare(value2) !== 0)
return false;
}
else // Comparing as two ArrayBuffers
{
if (isEqualBuffer(this.value.valueBeforeDecode, compareTo.value.valueBeforeDecode) === false)
if(isEqualBuffer(this.value.valueBeforeDecode, compareTo.value.valueBeforeDecode) === false)
return false;
}

return true;
}

if (compareTo instanceof ArrayBuffer)
if(compareTo instanceof ArrayBuffer)
return isEqualBuffer(this.value.valueBeforeDecode, compareTo);

return false;
}
//**********************************************************************************
/**
* Convert an AttributeTypeAndValue to a human-readable string
* based on RFC4514, with escaping charaters
* based on RFC4514, with escaping characters
* @returns {string}
*/
toString() {
toString()
{
let value = this.value.valueBlock.value;

value = value.replace(/(["+,;<>\\=])/g, "\\$1");

if (value.startsWith(" ") || value.startsWith("#")) {
if(value.startsWith(" ") || value.startsWith("#"))
{
value = "\\" + value;
}
if (value.endsWith(" ")) {
if(value.endsWith(" "))
{
value = value.substring(0, value.length - 1) + "\\" + value.substring(value.length - 1);
}

Expand Down
Loading

0 comments on commit 3ea742d

Please sign in to comment.