SnmpKit.SnmpLib.Types.Validation (snmpkit v2.0.1)

Range and shape validation for SNMP values (Counter32/64, Gauge32, TimeTicks, Unsigned32, INTEGER, OCTET STRING, OID, IpAddress, Opaque). SnmpKit.SnmpLib.Types delegates here.

Summary

Functions

Validates an SNMP integer value.

Validates an IP address value.

Validates an OCTET STRING value.

Validates an OBJECT IDENTIFIER value.

Validates an Opaque value.

@spec encode_value(term(), keyword()) :: {:ok, {snmp_type(), term()}} | {:error, atom()}

Functions

validate_integer(value)

@spec validate_integer(term()) :: :ok | {:error, atom()}

Validates an SNMP integer value.

SNMP INTEGER is a signed 32-bit integer.

validate_ip_address(value)

@spec validate_ip_address(term()) :: :ok | {:error, atom()}

Validates an IP address value.

IP address should be a 4-byte binary or a tuple of 4 integers.

Examples

:ok = SnmpKit.SnmpLib.Types.validate_ip_address(<<192, 168, 1, 1>>)
:ok = SnmpKit.SnmpLib.Types.validate_ip_address({192, 168, 1, 1})
{:error, :invalid_length} = SnmpKit.SnmpLib.Types.validate_ip_address(<<192, 168, 1>>)

validate_octet_string(value)

@spec validate_octet_string(term()) :: :ok | {:error, atom()}

Validates an OCTET STRING value.

OCTET STRING should be a binary with reasonable length limits.

validate_oid(oid)

@spec validate_oid(term()) :: :ok | {:error, atom()}

Validates an OBJECT IDENTIFIER value.

OID should be a list of non-negative integers.

validate_opaque(value)

@spec validate_opaque(term()) :: :ok | {:error, atom()}

Validates an Opaque value.

Opaque is used for arbitrary binary data.

validate_timeticks(value)

@spec validate_timeticks(term()) :: :ok | {:error, atom()}

@spec encode_value(term(), keyword()) :: {:ok, {snmp_type(), term()}} | {:error, atom()}

@doc """ Validates a TimeTicks value.

TimeTicks represents time in hundredths of a second (centiseconds).