summaryrefslogtreecommitdiff
path: root/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py
diff options
context:
space:
mode:
Diffstat (limited to 'pysnmp/proto/secmod/rfc3414/auth/hmacsha.py')
-rw-r--r--pysnmp/proto/secmod/rfc3414/auth/hmacsha.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py b/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py
index 3efe9c49..8776f6fb 100644
--- a/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py
+++ b/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py
@@ -10,21 +10,23 @@ except ImportError:
import sha
sha1 = sha.new
+
from pyasn1.type import univ
from pysnmp.proto.secmod.rfc3414.auth import base
from pysnmp.proto.secmod.rfc3414 import localkey
from pysnmp.proto import errind, error
-_twelveZeros = univ.OctetString((0,) * 12).asOctets()
-_fortyFourZeros = (0,) * 44
+TWELVE_ZEROS = univ.OctetString((0,) * 12).asOctets()
+FORTY_FOUR_ZEROS = (0,) * 44
# 7.2.4
class HmacSha(base.AbstractAuthenticationService):
- serviceID = (1, 3, 6, 1, 6, 3, 10, 1, 1, 3) # usmHMACSHAAuthProtocol
- __ipad = [0x36] * 64
- __opad = [0x5C] * 64
+ SERVICE_ID = (1, 3, 6, 1, 6, 3, 10, 1, 1, 3) # usmHMACSHAAuthProtocol
+
+ IPAD = [0x36] * 64
+ OPAD = [0x5C] * 64
def hashPassphrase(self, authKey):
return localkey.hashPassphraseSHA(authKey)
@@ -43,27 +45,27 @@ class HmacSha(base.AbstractAuthenticationService):
# should be in the substrate. Also, it pre-sets digest placeholder
# so we hash wholeMsg out of the box.
# Yes, that's ugly but that's rfc...
- l = wholeMsg.find(_twelveZeros)
+ l = wholeMsg.find(TWELVE_ZEROS)
if l == -1:
raise error.ProtocolError('Cant locate digest placeholder')
wholeHead = wholeMsg[:l]
wholeTail = wholeMsg[l + 12:]
# 7.3.1.2a
- extendedAuthKey = authKey.asNumbers() + _fortyFourZeros
+ extendedAuthKey = authKey.asNumbers() + FORTY_FOUR_ZEROS
# 7.3.1.2b -- no-op
# 7.3.1.2c
k1 = univ.OctetString(
- map(lambda x, y: x ^ y, extendedAuthKey, self.__ipad)
+ map(lambda x, y: x ^ y, extendedAuthKey, self.IPAD)
)
# 7.3.1.2d -- no-op
# 7.3.1.2e
k2 = univ.OctetString(
- map(lambda x, y: x ^ y, extendedAuthKey, self.__opad)
+ map(lambda x, y: x ^ y, extendedAuthKey, self.OPAD)
)
# 7.3.1.3
@@ -90,23 +92,23 @@ class HmacSha(base.AbstractAuthenticationService):
raise error.ProtocolError('Cant locate digest in wholeMsg')
wholeHead = wholeMsg[:l]
wholeTail = wholeMsg[l + 12:]
- authenticatedWholeMsg = wholeHead + _twelveZeros + wholeTail
+ authenticatedWholeMsg = wholeHead + TWELVE_ZEROS + wholeTail
# 7.3.2.4a
- extendedAuthKey = authKey.asNumbers() + _fortyFourZeros
+ extendedAuthKey = authKey.asNumbers() + FORTY_FOUR_ZEROS
# 7.3.2.4b --> no-op
# 7.3.2.4c
k1 = univ.OctetString(
- map(lambda x, y: x ^ y, extendedAuthKey, self.__ipad)
+ map(lambda x, y: x ^ y, extendedAuthKey, self.IPAD)
)
# 7.3.2.4d --> no-op
# 7.3.2.4e
k2 = univ.OctetString(
- map(lambda x, y: x ^ y, extendedAuthKey, self.__opad)
+ map(lambda x, y: x ^ y, extendedAuthKey, self.OPAD)
)
# 7.3.2.5a