<s> from synapse . crypto . event_signing import * <EOL> from unpaddedbase64 import encode_base64 <EOL> import argparse <EOL> import hashlib <EOL> import sys <EOL> import json <EOL> class dictobj ( dict ) : <EOL> def __init__ ( self , * args , ** kargs ) : <EOL> dict . __init__ ( self , * args , ** kargs ) <EOL> self . __dict__ = self <EOL> def get_dict ( self ) : <EOL> return dict ( self ) <EOL> def get_full_dict ( self ) : <EOL> return dict ( self ) <EOL> def get_pdu_json ( self ) : <EOL> return dict ( self ) <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( "<STR_LIT>" , nargs = "<STR_LIT:?>" , type = argparse . FileType ( '<STR_LIT:r>' ) , <EOL> default = sys . stdin ) <EOL> args = parser . parse_args ( ) <EOL> logging . basicConfig ( ) <EOL> event_json = dictobj ( json . load ( args . input_json ) ) <EOL> algorithms = { <EOL> "<STR_LIT>" : hashlib . sha256 , <EOL> } <EOL> for alg_name in event_json . hashes : <EOL> if check_event_content_hash ( event_json , algorithms [ alg_name ] ) : <EOL> print "<STR_LIT>" % ( alg_name , ) <EOL> else : <EOL> print "<STR_LIT>" % ( alg_name , ) <EOL> for algorithm in algorithms . values ( ) : <EOL> name , h_bytes = compute_event_reference_hash ( event_json , algorithm ) <EOL> print "<STR_LIT>" % ( name , encode_base64 ( h_bytes ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
