File: md5sum.py

package info (click to toggle)
python-cpl 0.3.6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 500 kB
  • sloc: python: 2,448; ansic: 1,334; sh: 357; makefile: 48
file content (21 lines) | stat: -rw-r--r-- 564 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os 
import hashlib

def datamd5(hdulist):
    '''Calculate the MD5SUM of all data regions of a HDUList.
    '''
    sum = hashlib.md5()
    for hdu in hdulist:
        if hdu.data is not None:
            sum.update(hdu.data)
            pad = '\0' * (2880 - hdu.data.nbytes % 2880)
            sum.update(pad)
    return sum.hexdigest()

def verify_md5(hdulist):
    return hdulist[0].header.get('DATAMD5') == datamd5(hdulist)

def update_md5(hdulist):
    sum = datamd5(hdulist)
    hdulist[0].header.update('DATAMD5', sum, 'MD5 checksum')
    return sum