<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Setup command line client
Step1:  Describes the tests needed to validate the GetChecksums functionality.
Upload a file with a known checksum for so we have something to test on
Step2:  Basic getChecksum
Step3:  Request the checksum of a file in the collection.
Step4:  The correct checksum should be returned by all the pillars.
getChecksum (salted)
Request the salted checksum of a file in the collection
Step5:  The correct salted checksum should be returned by all the pillars (except the ChecksumPillar).
Missing file
Request the checksum of a file that does not exist in the collection.
<ASSISTANT_TASK:>
Python Code:
%env CLIENT bitrepository-client-1.9-RC1
!wget -Nq "https://sbforge.org/download/attachments/25395346/${CLIENT}.zip"
!unzip -quo ${CLIENT}.zip
%alias bitmag ${CLIENT}/bin/bitmag.sh %l
Explanation: Setup command line client
End of explanation
%env TESTFILE1 README.md
%bitmag put-file -c integrationtest1 -f $TESTFILE1 -i $TESTFILE1
Explanation: Describes the tests needed to validate the GetChecksums functionality.
Upload a file with a known checksum for so we have something to test on
End of explanation
!md5sum $TESTFILE1
Explanation: Basic getChecksum
End of explanation
%bitmag get-checksums -c integrationtest1 -i $TESTFILE1
Explanation: Request the checksum of a file in the collection.
End of explanation
import hmac
import hashlib
import base64
def getSaltedChecksum(file,saltHex,algorithm):
    #Note, the salt is a hex string
    salt = bytearray.fromhex(saltHex)
    digester = hmac.new(salt,None,algorithm)
    with open(file,'rb') as from_fh:
        while True:
            chunk = from_fh.read()
            if not chunk:
                break
            digester.update(chunk)
    return digester.hexdigest().lower()
file = os.environ.get('TESTFILE1')
print(getSaltedChecksum(file,saltHex='abcd',algorithm=hashlib.md5))
%bitmag get-checksums -c integrationtest1 -i $TESTFILE1 -R HMAC_MD5 -S 'abcd'
Explanation: The correct checksum should be returned by all the pillars.
getChecksum (salted)
Request the salted checksum of a file in the collection
End of explanation
%bitmag get-checksums -c integrationtest1 -i ThisFileDoesNotExist
Explanation: The correct salted checksum should be returned by all the pillars (except the ChecksumPillar).
Missing file
Request the checksum of a file that does not exist in the collection.
End of explanation
<END_TASK>