def encrypt(self, data_bio, flags=0): if not hasattr(self, 'cipher'): raise SMIME_Error, 'no cipher: use set_cipher()' if not hasattr(self, 'x509_stack'): raise SMIME_Error, 'no recipient certs: use set_x509_stack()' pkcs7 = m2.pkcs7_encrypt(self.x509_stack._ptr(), data_bio._ptr(), self.cipher._ptr(), flags) if pkcs7 is None: raise SMIME_Error, Err.get_error() return PKCS7(pkcs7, 1)
def decrypt(self, pkcs7, flags=0): if not hasattr(self, 'pkey'): raise SMIME_Error, 'no private key: use load_key()' if not hasattr(self, 'x509'): raise SMIME_Error, 'no certificate: load_key() used incorrectly?' blob = m2.pkcs7_decrypt(pkcs7._ptr(), self.pkey._ptr(), self.x509._ptr(), flags) if blob is None: raise SMIME_Error, Err.get_error() return blob
def load_pkcs7(p7file): bio = m2.bio_new_file(p7file, 'r') if bio is None: raise Err.get_error() try: p7_ptr = m2.pkcs7_read_bio(bio) finally: m2.bio_free(bio) if p7_ptr is None: raise Err.get_error() return PKCS7(p7_ptr, 1)
def sign(self, data_bio, flags=0): if not hasattr(self, "pkey"): raise SMIME_Error, "no private key: use load_key()" if hasattr(self, "x509_stack"): pkcs7 = m2.pkcs7_sign1(self.x509._ptr(), self.pkey._ptr(), self.x509_stack._ptr(), data_bio._ptr(), flags) if pkcs7 is None: raise SMIME_Error(Err.get_error()) return PKCS7(pkcs7, 1) else: pkcs7 = m2.pkcs7_sign0(self.x509._ptr(), self.pkey._ptr(), data_bio._ptr(), flags) if pkcs7 is None: raise SMIME_Error(Err.get_error()) return PKCS7(pkcs7, 1)
def load_pkcs7(p7file): bio = m2.bio_new_file(p7file, "r") if bio is None: raise BIO.BIOError(Err.get_error()) try: p7_ptr = m2.pkcs7_read_bio(bio) finally: m2.bio_free(bio) if p7_ptr is None: raise PKCS7_Error(Err.get_error()) return PKCS7(p7_ptr, 1)
def verify(self, pkcs7, data_bio=None, flags=0): if not hasattr(self, 'x509_stack'): raise SMIME_Error, 'no signer certs: use set_x509_stack()' if not hasattr(self, 'x509_store'): raise SMIME_Error, 'no x509 cert store: use set_x509_store()' assert isinstance(pkcs7, PKCS7), 'pkcs7 not an instance of PKCS7' p7 = pkcs7._ptr() if data_bio is None: blob = m2.pkcs7_verify0(p7, self.x509_stack._ptr(), self.x509_store._ptr(), flags) else: blob = m2.pkcs7_verify1(p7, self.x509_stack._ptr(), self.x509_store._ptr(), data_bio._ptr(), flags) if blob is None: raise SMIME_Error, Err.get_error() return blob
def text_crlf_bio(bio_in): bio_out = BIO.MemoryBuffer() m2.smime_crlf_copy(bio_in, bio_out) if m2.smime_crlf_copy(bio_in, bio_out): return bio_out else: raise Err.get_error()
def text_crlf(text): bio_in = BIO.MemoryBuffer(text) bio_out = BIO.MemoryBuffer() if m2.smime_crlf_copy(bio_in, bio_out): return bio_out.read() else: raise Err.get_error()
def sign(self, data_bio, flags=0): if not hasattr(self, 'pkey'): raise SMIME_Error, 'no private key: use load_key()' if hasattr(self, 'x509_stack'): pkcs7 = m2.pkcs7_sign1(self.x509._ptr(), self.pkey._ptr(), self.x509_stack._ptr(), data_bio._ptr(), flags) if pkcs7 is None: raise SMIME_Error, Err.get_error() return PKCS7(pkcs7, 1) else: pkcs7 = m2.pkcs7_sign0(self.x509._ptr(), self.pkey._ptr(), data_bio._ptr(), flags) if pkcs7 is None: raise SMIME_Error, Err.get_error() return PKCS7(pkcs7, 1)
def smime_load_pkcs7(p7file): bio = m2.bio_new_file(p7file, 'r') if bio is None: raise Err.get_error() try: p7_ptr, bio_ptr = m2.smime_read_pkcs7(bio) finally: m2.bio_free(bio) if p7_ptr is None: raise Err.get_error() if bio_ptr is None: return PKCS7(p7_ptr, 1), None else: return PKCS7(p7_ptr, 1), BIO.BIO(bio_ptr, 1)
def smime_load_pkcs7(p7file): bio = m2.bio_new_file(p7file, "r") if bio is None: raise BIO.BIOError(Err.get_error()) try: p7_ptr, bio_ptr = m2.smime_read_pkcs7(bio) finally: m2.bio_free(bio) if p7_ptr is None: raise SMIME_Error(Err.get_error()) if bio_ptr is None: return PKCS7(p7_ptr, 1), None else: return PKCS7(p7_ptr, 1), BIO.BIO(bio_ptr, 1)
def __init__(self, input, out_file): # input是输入字符串,outfile是输出的文件 self.lex = word_anay.word_anay(input) # 词法分析器 self.line = 1 # 初始行数 self.nextsym() # 符号 self.table = SymbolTable.SymbolTable() # 符号表 self.interp = Interpreter.Interpreter(out_file) self.myErr = Err.Err(out_file) # 错误处理 self.declbegsys = set() self.declbegsys.add('CONST') self.declbegsys.add('VAR') self.declbegsys.add('PROCEDURE') # 表示申明开始的符号集合:声明的FIRST集合 self.statbegsys = set() self.statbegsys.add('BEGIN') self.statbegsys.add('CALL') self.statbegsys.add('IF') self.statbegsys.add('WHILE') self.statbegsys.add('REPEAT') # 表示语句开始的符号集合:语句的FIRST集合 self.facbegsys = set() # 表示因子开始的符号集合:因子的FIRST集合 self.facbegsys.add('ID') self.facbegsys.add('NUMBER') self.facbegsys.add('LPAREN') # 当前作用域的堆栈帧大小,或者说数据大小(datasize) # 计算每个变量在运行栈中相对本过程基地址的偏移量 # 放在symbolTable中的address域 # 生成目标代码时再放在code中的a域 self.dx = 0
def text_crlf(text): bio_in = BIO.MemoryBuffer(text) bio_out = BIO.MemoryBuffer() if m2.smime_crlf_copy(bio_in._ptr(), bio_out._ptr()): return bio_out.read() else: raise SMIME_Error(Err.get_error())
def smime_load_pkcs7_bio(p7_bio): p7_ptr, bio_ptr = m2.smime_read_pkcs7(p7_bio._ptr()) if p7_ptr is None: raise SMIME_Error(Err.get_error()) if bio_ptr is None: return PKCS7(p7_ptr, 1), None else: return PKCS7(p7_ptr, 1), BIO.BIO(bio_ptr, 1)
def smime_load_pkcs7_bio(p7_bio): p7_ptr, bio_ptr = m2.smime_read_pkcs7(p7_bio._ptr()) if p7_ptr is None: raise Err.get_error() if bio_ptr is None: return PKCS7(p7_ptr, 1), None else: return PKCS7(p7_ptr, 1), BIO.BIO(bio_ptr, 1)
def decrypt(self, pkcs7, flags=0): if not hasattr(self, "pkey"): raise SMIME_Error, "no private key: use load_key()" if not hasattr(self, "x509"): raise SMIME_Error, "no certificate: load_key() used incorrectly?" blob = m2.pkcs7_decrypt(pkcs7._ptr(), self.pkey._ptr(), self.x509._ptr(), flags) if blob is None: raise SMIME_Error(Err.get_error()) return blob
def sign_raw(self, data_bio, flags=0, md=m2.NID_sha1): if not hasattr(self, 'pkey'): raise SMIME_Error, 'no private key: use load_key()' if hasattr(self, 'x509_stack'): pkcs7 = m2.pkcs7_sign_raw1(self.x509._ptr(), self.pkey._ptr(), self.x509_stack._ptr(), data_bio._ptr(), flags, md) if pkcs7 is None: raise SMIME_Error(Err.get_error()) return PKCS7(pkcs7, 1) else: return None
def load_pkcs7_bio(p7_bio): p7_ptr = m2.pkcs7_read_bio(p7_bio._ptr()) if p7_ptr is None: raise PKCS7_Error(Err.get_error()) return PKCS7(p7_ptr, 1)
def text_crlf_bio(bio_in): bio_out = BIO.MemoryBuffer() if m2.smime_crlf_copy(bio_in._ptr(), bio_out._ptr()): return bio_out else: raise SMIME_Error(Err.get_error())
def load_pkcs7_bio(p7_bio): p7_ptr = m2.pkcs7_read_bio(p7_bio._ptr()) if p7_ptr is None: raise Err.get_error() return PKCS7(p7_ptr, 1)
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e): #print("line " + str(line) + ":" + str(column) + " " + msg, file=sys.stderr) Err.addError(msg, Err.errFile, "line " + str(line) + ":" + str(column))