Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Unified Diff: third_party/gsutil/third_party/pyasn1-modules/pyasn1_modules/pem.py

Issue 1377933002: [catapult] - Copy Telemetry's gsutilz over to third_party. (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: Rename to gsutil. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/gsutil/third_party/pyasn1-modules/pyasn1_modules/pem.py
diff --git a/third_party/gsutil/third_party/pyasn1-modules/pyasn1_modules/pem.py b/third_party/gsutil/third_party/pyasn1-modules/pyasn1_modules/pem.py
new file mode 100644
index 0000000000000000000000000000000000000000..d8d815873e9b123fe41afdc8eb058855769f22a2
--- /dev/null
+++ b/third_party/gsutil/third_party/pyasn1-modules/pyasn1_modules/pem.py
@@ -0,0 +1,51 @@
+import base64, 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 = ''
+ state = stSpam
+ while 1:
+ certLine = fileObj.readline()
+ if not certLine:
+ break
+ certLine = certLine.strip()
+ if state == stSpam:
+ if certLine in startMarkers:
+ certLines = []
+ idx = startMarkers[certLine]
+ state = stHam
+ continue
+ if state == stHam:
+ if certLine in stopMarkers and stopMarkers[certLine] == idx:
+ state = stDump
+ else:
+ certLines.append(certLine)
+ if state == stDump:
+ if sys.version_info[0] <= 2:
+ substrate = ''.join([ base64.b64decode(x) for x in certLines ])
+ else:
+ substrate = ''.encode().join([ base64.b64decode(x.encode()) for x in certLines ])
+ break
+ return idx, substrate
+
+# Backward compatibility routine
+def readPemFromFile(fileObj,
+ startMarker='-----BEGIN CERTIFICATE-----',
+ endMarker='-----END CERTIFICATE-----'):
+ idx, substrate = readPemBlocksFromFile(fileObj, (startMarker, endMarker))
+ return substrate
+
+def readBase64FromFile(fileObj):
+ if sys.version_info[0] <= 2:
+ return ''.join([ base64.b64decode(x) for x in fileObj.readlines() ])
+ else:
+ return ''.encode().join(
+ [ base64.b64decode(x.encode()) for x in fileObj.readlines() ]
+ )

Powered by Google App Engine
This is Rietveld 408576698