mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-29 18:31:38 +00:00
upgrade pyasn1_modules to 0.1.4
This commit is contained in:
@@ -1,17 +1,27 @@
|
||||
import base64, sys
|
||||
#
|
||||
# This file is part of pyasn1-modules software.
|
||||
#
|
||||
# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
|
||||
# License: http://pyasn1.sf.net/license.html
|
||||
#
|
||||
import base64
|
||||
import sys
|
||||
|
||||
stSpam, stHam, stDump = 0, 1, 2
|
||||
|
||||
|
||||
# The markers parameters is in form ('start1', 'stop1'), ('start2', 'stop2')...
|
||||
# Return is (marker-index, substrate)
|
||||
def readPemBlocksFromFile(fileObj, *markers):
|
||||
startMarkers = dict(map(lambda x: (x[1],x[0]),
|
||||
enumerate(map(lambda x: x[0], markers))))
|
||||
stopMarkers = dict(map(lambda x: (x[1],x[0]),
|
||||
enumerate(map(lambda x: x[1], markers))))
|
||||
idx = -1; substrate = ''
|
||||
startMarkers = dict(map(lambda x: (x[1], x[0]),
|
||||
enumerate(map(lambda y: y[0], markers))))
|
||||
stopMarkers = dict(map(lambda x: (x[1], x[0]),
|
||||
enumerate(map(lambda y: y[1], markers))))
|
||||
idx = -1
|
||||
substrate = ''
|
||||
certLines = []
|
||||
state = stSpam
|
||||
while 1:
|
||||
while True:
|
||||
certLine = fileObj.readline()
|
||||
if not certLine:
|
||||
break
|
||||
@@ -29,23 +39,27 @@ def readPemBlocksFromFile(fileObj, *markers):
|
||||
certLines.append(certLine)
|
||||
if state == stDump:
|
||||
if sys.version_info[0] <= 2:
|
||||
substrate = ''.join([ base64.b64decode(x) for x in certLines ])
|
||||
substrate = ''.join([base64.b64decode(x) for x in certLines])
|
||||
else:
|
||||
substrate = ''.encode().join([ base64.b64decode(x.encode()) for x in certLines ])
|
||||
substrate = ''.encode().join([base64.b64decode(x.encode()) for x in certLines])
|
||||
break
|
||||
return idx, substrate
|
||||
|
||||
|
||||
# Backward compatibility routine
|
||||
def readPemFromFile(fileObj,
|
||||
def readPemFromFile(fileObj,
|
||||
startMarker='-----BEGIN CERTIFICATE-----',
|
||||
endMarker='-----END CERTIFICATE-----'):
|
||||
idx, substrate = readPemBlocksFromFile(fileObj, (startMarker, endMarker))
|
||||
return substrate
|
||||
|
||||
def readBase64FromFile(fileObj):
|
||||
|
||||
def readBase64fromText(text):
|
||||
if sys.version_info[0] <= 2:
|
||||
return ''.join([ base64.b64decode(x) for x in fileObj.readlines() ])
|
||||
return base64.b64decode(text)
|
||||
else:
|
||||
return ''.encode().join(
|
||||
[ base64.b64decode(x.encode()) for x in fileObj.readlines() ]
|
||||
)
|
||||
return base64.b64decode(text.encode())
|
||||
|
||||
|
||||
def readBase64FromFile(fileObj):
|
||||
return readBase64fromText(fileObj.read())
|
||||
|
||||
Reference in New Issue
Block a user