<s> import argparse <EOL> import hashlib <EOL> import base64 <EOL> import hmac <EOL> def parse_args ( ) : <EOL> """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT:key>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> return parser . parse_args ( ) <EOL> def string_to_sign ( ) : <EOL> return '<STR_LIT:\n>' . join ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def raw_sign ( message , secret ) : <EOL> """<STR_LIT>""" <EOL> digest = hmac . new ( secret , message , hashlib . sha256 ) . digest ( ) <EOL> return base64 . b64encode ( digest ) <EOL> def http_signature ( message , key_id , signature ) : <EOL> """<STR_LIT>""" <EOL> template = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> headers = [ '<STR_LIT>' , '<STR_LIT:host>' , '<STR_LIT>' , '<STR_LIT:date>' ] <EOL> return template % { <EOL> '<STR_LIT>' : key_id , <EOL> '<STR_LIT>' : signature , <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' . join ( headers ) , <EOL> } <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> args = parse_args ( ) <EOL> message = string_to_sign ( ) <EOL> signature = raw_sign ( message , args . key ) <EOL> header = http_signature ( message , args . key_id , signature ) <EOL> print "<STR_LIT>" <EOL> print signature <EOL> print "<STR_LIT>" <EOL> print header </s>
