net-snmp 3.18.1 → 3.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3457,6 +3457,14 @@ Example programs are included under the module's `example` directory.
3457
3457
 
3458
3458
  * Add agent option key for MIB options
3459
3459
 
3460
+ ## Version 3.18.2 - 06/01/2025
3461
+
3462
+ * Add conversion of scalar defVal enumeration name to number on assignment
3463
+
3464
+ ## Version 3.19.0 - 06/02/2025
3465
+
3466
+ * Remove deprecated isArray call and fix agent string constraints check
3467
+
3460
3468
  # License
3461
3469
 
3462
3470
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -682,7 +682,7 @@ ObjectTypeUtil.isValid = function (type, value, constraints) {
682
682
  if ( typeof value != "string" && ! (value instanceof Buffer) ) {
683
683
  return false;
684
684
  }
685
- if ( constraints && ObjectTypeUtil.doesStringMeetConstraints (value, constraints) ) {
685
+ if ( constraints && ! ObjectTypeUtil.doesStringMeetConstraints (value, constraints) ) {
686
686
  return false;
687
687
  }
688
688
  return true;
@@ -783,6 +783,15 @@ ObjectTypeUtil.doesStringMeetConstraints = function (value, constraints) {
783
783
  return true;
784
784
  };
785
785
 
786
+ ObjectTypeUtil.getEnumerationNumberFromName = function (enumeration, name) {
787
+ for ( const [enumNumber, enumName] of Object.entries (enumeration) ) {
788
+ if ( enumName === name ) {
789
+ return Number (enumNumber);
790
+ }
791
+ }
792
+ return null;
793
+ };
794
+
786
795
  /*****************************************************************************
787
796
  ** PDU class definitions
788
797
  **/
@@ -4199,10 +4208,15 @@ Mib.prototype.populateIndexEntryFromColumn = function (localProvider, indexEntry
4199
4208
  Mib.prototype.registerProvider = function (provider) {
4200
4209
  this.providers[provider.name] = provider;
4201
4210
  if ( provider.type == MibProviderType.Scalar ) {
4202
- if ( this.options?.addScalarDefaultsOnRegistration ) {
4203
- if ( provider.defVal ) {
4204
- this.setScalarValue (provider.name, provider.defVal);
4211
+ if ( this.options?.addScalarDefaultsOnRegistration && provider.defVal ) {
4212
+ let scalarValue;
4213
+ // If the scalar has an enumeration, set the value to the enumeration number derived from the defVal name
4214
+ if ( provider.constraints?.enumeration ) {
4215
+ scalarValue = ObjectTypeUtil.getEnumerationNumberFromName (provider.constraints.enumeration, provider.defVal);
4216
+ } else {
4217
+ scalarValue = provider.defVal;
4205
4218
  }
4219
+ this.setScalarValue (provider.name, scalarValue);
4206
4220
  }
4207
4221
  } else if ( provider.type == MibProviderType.Table ) {
4208
4222
  if ( provider.tableAugments ) {
@@ -4709,7 +4723,7 @@ Mib.convertOidToAddress = function (oid) {
4709
4723
  var oidArray;
4710
4724
  var i;
4711
4725
 
4712
- if (typeof (oid) === 'object' && util.isArray(oid)) {
4726
+ if (typeof (oid) === 'object' && Array.isArray(oid)) {
4713
4727
  address = oid;
4714
4728
  } else if (typeof (oid) === 'string') {
4715
4729
  address = oid.split('.');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.18.1",
3
+ "version": "3.19.0",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -85,6 +85,22 @@ describe('Object Types', function() {
85
85
  assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, Buffer.from('1.3.6.1.2.3.4.5')), true);
86
86
  });
87
87
  });
88
+ describe('A string with a length of 6 is valid for a size range of 2 - 7', function() {
89
+ it('returns true', function() {
90
+ const sizes = [
91
+ { min: 2, max: 7 },
92
+ ];
93
+ assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, 'sixlet', { sizes }), true);
94
+ });
95
+ });
96
+ describe('A string with a length of 6 is not valid for a size range of 2 - 5', function() {
97
+ it('returns true', function() {
98
+ const sizes = [
99
+ { min: 2, max: 5 },
100
+ ];
101
+ assert.equal(snmp.ObjectTypeUtil.isValid(snmp.ObjectType.OctetString, 'sixlet', { sizes }), false);
102
+ });
103
+ });
88
104
  });
89
105
 
90
106
  describe('isValid() - OID', function() {