我们从Python开源项目中,提取了以下41个代码示例,用于说明如何使用pyasn1.type.univ.Null()。
def valueDecoder(self, substrate, asn1Spec, tagSet=None, length=None, state=None, decodeFun=None, substrateFun=None, **options): if tagSet[0].tagFormat != tag.tagFormatSimple: raise error.PyAsn1Error('Simple tag format expected') head, tail = substrate[:length], substrate[length:] component = self._createComponent(asn1Spec, tagSet) if head: raise error.PyAsn1Error('Unexpected %d-octet substrate for Null' % length) return component, tail
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] r = self._createComponent(asn1Spec, tagSet) if head: raise error.PyAsn1Error('Unexpected %d-octet substrate for Null' % length) return r, tail
def _ValidateEmptyParams(self, params): if params: param_value, rest = decoder.decode(params) if rest: raise Asn1Error('Extra unparsed content.') if param_value != univ.Null(): raise Asn1Error('Hasher has parameters. No idea what to do with them.')
def __init__(self, oid=None, value=univ.Null): self.oid = oid self.default_value = value
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length, state, decodeFun, substrateFun): head, tail = substrate[:length], substrate[length:] component = self._createComponent(asn1Spec, tagSet) if head: raise error.PyAsn1Error('Unexpected %d-octet substrate for Null' % length) return component, tail
def __assemble_hmac_block(self, content, key): """ Produce HMAC block ASN.1 structure (MPHMACContainer) @developer: vsmysle :param content: string DER-encoded content generate HMAC of and encapsulate into HMAC FLOD block :param key: bytes key to use for HMAC generation :return: DER-encoded ASN.1 structure that encapsulates HMAC block """ # TODO: add exceptions self.logger.debug("producing HMAC block with ASN.1 structure") # calculating hmac digest of content digest = self.__generate_hmac(content, key) # oid for SHA1 hash function oid = const.SHA1_OID # creating instance of AlgorithmIdentifier class ai = asn1_dec.AlgorithmIdentifier() # setting corresponding parameters ai['algorithm'] = oid ai['parameters'] = univ.Null() # creating instance of MPHMACContainer class hmac_block = asn1_dec.MPHMACContainer() # setting corresponding parameters hmac_block['digestAlgorithm'] = ai hmac_block['digest'] = digest return hmac_block
def __get_asn1_algorithm_identifier(self, oid_str): """ Generate ASN.1 structure for algorithm identifier @developer: vsmysle :param oid_str: string OID to encapsulate :return: pyasn1.type.univ.Sequence object """ # TODO: add exceptions # log entry self.logger.debug("creating AlgorithmIdentifier ASN.1 " "structure with OID=%s" % oid_str) # create the instance of AlgorithmIdentifier ai = asn1_dec.AlgorithmIdentifier() # set corresponding parameters ai['algorithm'] = oid_str ai['parameters'] = univ.Null() # return the result return ai
def evaluateValue(self, oid, tag, value, **context): # Variation module reference if ':' in tag: modName, tag = tag[tag.index(':')+1:], tag[:tag.index(':')] else: modName = None if modName: if ('variationModules' in context and modName in context['variationModules']): if 'dataValidation' in context: return oid, tag, univ.Null else: if context['setFlag']: hexvalue = self.grammar.hexifyValue(context['origValue']) if hexvalue is not None: context['hexvalue'] = hexvalue context['hextag'] = self.grammar.getTagByType(context['origValue']) + 'x' # prepare agent and record contexts on first reference (variationModule, agentContexts, recordContexts) = context['variationModules'][modName] if context['dataFile'] not in agentContexts: agentContexts[context['dataFile']] = {} if context['dataFile'] not in recordContexts: recordContexts[context['dataFile']] = {} variationModule['agentContext'] = agentContexts[context['dataFile']] recordContexts = recordContexts[context['dataFile']] if oid not in recordContexts: recordContexts[oid] = {} variationModule['recordContext'] = recordContexts[oid] # invoke variation module oid, tag, value = variationModule['variate'](oid, tag, value, **context) else: raise SnmpsimError('Variation module "%s" referenced but not loaded\r\n' % modName) if not modName: if 'dataValidation' in context: snmprec.SnmprecRecord.evaluateValue( self, oid, tag, value, **context ) if (not context['nextFlag'] and not context['exactMatch'] or context['setFlag']): return context['origOid'], tag, context['errorStatus'] if not hasattr(value, 'tagSet'): # not already a pyasn1 object return snmprec.SnmprecRecord.evaluateValue( self, oid, tag, value, **context ) return oid, tag, value