def _readFileTextAndBinary(self, fname): try: # Read both binary (bytearray) and text (str) versions of the input try: if fname == "-": # Read as binary binary = readStdinBinary() else: binary = bytearray(open(fname, "rb").read()) text = bytesToStr(binary, "ascii") except UnicodeDecodeError: # So it must be a binary file, not text text = None return text, binary except IOError: self.printError("Error opening file: %s" % fname)
def getCertificate(self): certificateFile = self.argRemainder[1] try: if certificateFile == "-": # Read as binary certificateBytes = readStdinBinary() else: certificateBytes = bytearray( open(certificateFile, "rb").read()) return TlsCertificate.createFromBytes(certificateBytes) except SyntaxError as e: self.printError("Certificate malformed: %s\n%s" % (certificateFile, e)) except IOError as e: self.printError("Error opening certificate: %s\n%s" % (certificateFile, e))
def _getCertificate(self): certificateFile = self._getOptionValue("-c") if not certificateFile: self.printError("-c missing (Certificate)") try: if certificateFile == "-": # Read as binary certificateBytes = readStdinBinary() else: certificateBytes = bytearray(open(certificateFile, "rb").read()) return TlsCertificate.createFromBytes(certificateBytes) except SyntaxError: self.printError("Certificate malformed: %s" % certificateFile) except IOError: self.printError("Error opening certificate: %s" % certificateFile)
def getCertificate(self, mandatory): certificateFile = self._getOptionValue("-c") if not certificateFile: if mandatory: self.printError("-c missing (Certificate)") else: return None try: if certificateFile == "-": # Read as binary certificateBytes = readStdinBinary() else: certificateBytes = bytearray(open(certificateFile, "rb").read()) return TlsCertificate.createFromBytes(certificateBytes) except SyntaxError: self.printError("Certificate malformed: %s" % certificateFile) except IOError: self.printError("Error opening certificate: %s" % certificateFile)