diff options
author | chojoyce <chojoyce@google.com> | 2018-06-13 14:13:45 +0800 |
---|---|---|
committer | chojoyce <chojoyce@google.com> | 2018-06-13 14:26:23 +0800 |
commit | f2a0e87786f986785c7335f627250eff59168fb0 (patch) | |
tree | 62c5c35205bee146050e14cf5b56c4a0f95e4d6b /pyasn1_modules/rfc1155.py | |
parent | 52eef53175cb9e051125555c187fd7ac95464654 (diff) | |
parent | 5662c4308d3758d68e34398c1a70a346e58eb5a1 (diff) | |
download | pyasn1-modules-f2a0e87786f986785c7335f627250eff59168fb0.tar.gz |
Merge commit '5662c43' into pyasn1-modules_0.2.1android-p-preview-4
Initial commit of pyasn1-modules 0.2.1 with history.
Added:
- Android.bp
- MODULE_LICENSE_BSD
- NOTICE
- METADATA
Bug: b/80314772
Test: Compiled acloud with pyasn1-modules and was able to import pyasn1-modules.
Change-Id: I3f15a09e02bb7e6f12d8cc12eb999248463b98e4
Diffstat (limited to 'pyasn1_modules/rfc1155.py')
-rw-r--r-- | pyasn1_modules/rfc1155.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/pyasn1_modules/rfc1155.py b/pyasn1_modules/rfc1155.py new file mode 100644 index 0000000..69c160e --- /dev/null +++ b/pyasn1_modules/rfc1155.py @@ -0,0 +1,96 @@ +# +# This file is part of pyasn1-modules software. +# +# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com> +# License: http://pyasn1.sf.net/license.html +# +# SNMPv1 message syntax +# +# ASN.1 source from: +# http://www.ietf.org/rfc/rfc1155.txt +# +# Sample captures from: +# http://wiki.wireshark.org/SampleCaptures/ +# +from pyasn1.type import constraint +from pyasn1.type import namedtype +from pyasn1.type import tag +from pyasn1.type import univ + + +class ObjectName(univ.ObjectIdentifier): + pass + + +class SimpleSyntax(univ.Choice): + componentType = namedtype.NamedTypes( + namedtype.NamedType('number', univ.Integer()), + namedtype.NamedType('string', univ.OctetString()), + namedtype.NamedType('object', univ.ObjectIdentifier()), + namedtype.NamedType('empty', univ.Null()) + ) + + +class IpAddress(univ.OctetString): + tagSet = univ.OctetString.tagSet.tagImplicitly( + tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 0) + ) + subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint( + 4, 4 + ) + + +class NetworkAddress(univ.Choice): + componentType = namedtype.NamedTypes( + namedtype.NamedType('internet', IpAddress()) + ) + + +class Counter(univ.Integer): + tagSet = univ.Integer.tagSet.tagImplicitly( + tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 1) + ) + subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( + 0, 4294967295 + ) + + +class Gauge(univ.Integer): + tagSet = univ.Integer.tagSet.tagImplicitly( + tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 2) + ) + subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( + 0, 4294967295 + ) + + +class TimeTicks(univ.Integer): + tagSet = univ.Integer.tagSet.tagImplicitly( + tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 3) + ) + subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint( + 0, 4294967295 + ) + + +class Opaque(univ.OctetString): + tagSet = univ.OctetString.tagSet.tagImplicitly( + tag.Tag(tag.tagClassApplication, tag.tagFormatSimple, 4) + ) + + +class ApplicationSyntax(univ.Choice): + componentType = namedtype.NamedTypes( + namedtype.NamedType('address', NetworkAddress()), + namedtype.NamedType('counter', Counter()), + namedtype.NamedType('gauge', Gauge()), + namedtype.NamedType('ticks', TimeTicks()), + namedtype.NamedType('arbitrary', Opaque()) + ) + + +class ObjectSyntax(univ.Choice): + componentType = namedtype.NamedTypes( + namedtype.NamedType('simple', SimpleSyntax()), + namedtype.NamedType('application-wide', ApplicationSyntax()) + ) |