diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-08-03 02:33:27 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2017-08-03 03:00:55 +0200 |
commit | 18421d4bb5a69e8236675bd861acacb05d13dc70 (patch) | |
tree | 13f86ad930f925bf73b306f2b1b716dbb312a913 /pysnmp/proto/secmod/rfc3414 | |
parent | 69a2979d950184af03b1b75453e1a44c9f5197e5 (diff) | |
download | pysnmp-git-18421d4bb5a69e8236675bd861acacb05d13dc70.tar.gz |
refactor digest size getter into property, handle the case of unavailable crypto
Diffstat (limited to 'pysnmp/proto/secmod/rfc3414')
-rw-r--r-- | pysnmp/proto/secmod/rfc3414/auth/base.py | 5 | ||||
-rw-r--r-- | pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py | 3 | ||||
-rw-r--r-- | pysnmp/proto/secmod/rfc3414/auth/hmacsha.py | 3 | ||||
-rw-r--r-- | pysnmp/proto/secmod/rfc3414/priv/des.py | 8 | ||||
-rw-r--r-- | pysnmp/proto/secmod/rfc3414/service.py | 2 |
5 files changed, 12 insertions, 9 deletions
diff --git a/pysnmp/proto/secmod/rfc3414/auth/base.py b/pysnmp/proto/secmod/rfc3414/auth/base.py index 133416b8..37e8c4d7 100644 --- a/pysnmp/proto/secmod/rfc3414/auth/base.py +++ b/pysnmp/proto/secmod/rfc3414/auth/base.py @@ -15,8 +15,9 @@ class AbstractAuthenticationService(object): def localizeKey(self, authKey, snmpEngineID): raise error.ProtocolError(errind.noAuthentication) - - def getTagLen(self): + + @property + def digestLength(self): raise error.ProtocolError(errind.noAuthentication) # 7.2.4.1 diff --git a/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py b/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py index 13b27e10..907f1ce6 100644 --- a/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py +++ b/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py @@ -32,7 +32,8 @@ class HmacMd5(base.AbstractAuthenticationService): def localizeKey(self, authKey, snmpEngineID): return localkey.localizeKeyMD5(authKey, snmpEngineID) - def getTagLen(self): + @property + def digestLength(self): return 12 # 6.3.1 diff --git a/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py b/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py index 16cb2149..3ac7c33b 100644 --- a/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py +++ b/pysnmp/proto/secmod/rfc3414/auth/hmacsha.py @@ -32,7 +32,8 @@ class HmacSha(base.AbstractAuthenticationService): def localizeKey(self, authKey, snmpEngineID): return localkey.localizeKeySHA(authKey, snmpEngineID) - def getTagLen(self): + @property + def digestLength(self): return 12 # 7.3.1 diff --git a/pysnmp/proto/secmod/rfc3414/priv/des.py b/pysnmp/proto/secmod/rfc3414/priv/des.py index e38239ad..dd07d4d0 100644 --- a/pysnmp/proto/secmod/rfc3414/priv/des.py +++ b/pysnmp/proto/secmod/rfc3414/priv/des.py @@ -45,8 +45,8 @@ class Des(base.AbstractEncryptionService): hashAlgo = md5 elif authProtocol == hmacsha.HmacSha.serviceID: hashAlgo = sha1 - elif authProtocol in hmacsha2.HmacSha2.hashAlgo: - hashAlgo = hmacsha2.HmacSha2.hashAlgo[authProtocol] + elif authProtocol in hmacsha2.HmacSha2.hashAlgorithms: + hashAlgo = hmacsha2.HmacSha2.hashAlgorithms[authProtocol] else: raise error.ProtocolError( 'Unknown auth protocol %s' % (authProtocol,) @@ -58,8 +58,8 @@ class Des(base.AbstractEncryptionService): hashAlgo = md5 elif authProtocol == hmacsha.HmacSha.serviceID: hashAlgo = sha1 - elif authProtocol in hmacsha2.HmacSha2.hashAlgo: - hashAlgo = hmacsha2.HmacSha2.hashAlgo[authProtocol] + elif authProtocol in hmacsha2.HmacSha2.hashAlgorithms: + hashAlgo = hmacsha2.HmacSha2.hashAlgorithms[authProtocol] else: raise error.ProtocolError( 'Unknown auth protocol %s' % (authProtocol,) diff --git a/pysnmp/proto/secmod/rfc3414/service.py b/pysnmp/proto/secmod/rfc3414/service.py index d0a88c9c..714595c9 100644 --- a/pysnmp/proto/secmod/rfc3414/service.py +++ b/pysnmp/proto/secmod/rfc3414/service.py @@ -438,7 +438,7 @@ class SnmpUSMSecurityModel(AbstractSecurityModel): # extra-wild hack to facilitate BER substrate in-place re-write securityParameters.setComponentByPosition( - 4, '\x00' * authHandler.getTagLen() + 4, '\x00' * authHandler.digestLength ) debug.logger & debug.flagSM and debug.logger( |