MCPcopy Index your code
hub / github.com/apprenticeharper/DeDRM_tools / encryption

Function encryption

DeDRM_plugin/epubtest.py:170–197  ·  view source on GitHub ↗
(infile)

Source from the content-addressed store, hash-verified

168 return data
169
170def encryption(infile):
171 # returns encryption: one of Unencrypted, Adobe, B&N and Unknown
172 encryption = "Error When Checking."
173 try:
174 with open(infile,'rb') as infileobject:
175 bookdata = infileobject.read(58)
176 # Check for Zip
177 if bookdata[0:0+2] == b"PK":
178 foundrights = False
179 foundencryption = False
180 inzip = zipfile.ZipFile(infile,'r')
181 namelist = set(inzip.namelist())
182 if 'META-INF/rights.xml' not in namelist or 'META-INF/encryption.xml' not in namelist:
183 encryption = "Unencrypted"
184 else:
185 rights = etree.fromstring(inzip.read('META-INF/rights.xml'))
186 adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
187 expr = './/%s' % (adept('encryptedKey'),)
188 bookkey = ''.join(rights.findtext(expr))
189 if len(bookkey) == 172:
190 encryption = "Adobe"
191 elif len(bookkey) == 64:
192 encryption = "B&N"
193 else:
194 encryption = "Unknown"
195 except:
196 traceback.print_exc()
197 return encryption
198
199def main():
200 argv=unicode_argv()

Callers 1

mainFunction · 0.85

Calls 3

namelistMethod · 0.95
readMethod · 0.95
readMethod · 0.45

Tested by

no test coverage detected