コード例 #1
0
ファイル: Command.py プロジェクト: sambacha/anubis_py
    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)
コード例 #2
0
ファイル: Command.py プロジェクト: sambacha/anubis_py
    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))
コード例 #3
0
ファイル: Command.py プロジェクト: eaescob/tackpy
    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)
コード例 #4
0
ファイル: SignCommand.py プロジェクト: altoplano/TACKpy
    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)
コード例 #5
0
    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)