#NEWLINE# def get_signed_item( item , public_key , private_key , expires = None ) : #NEWLINE# #INDENT# '\n    Returns a copy of the passed in item that has been signed using the\n    private_key and annotated with metadata under the "_p4p2p" key (a\n    timestamp indicating when the message was signed, a timestamp indicating\n    when the item should expire, the p4p2p version that created the item, the\n    public_key and the signature).\n\n    The expiration timestamp is derived by adding the (optional) expires\n    number of seconds to the timestamp. If no expiration is specified then the\n    "expires" value is set to 0.0 (expiration is expressed as a float).\n    ' #NEWLINE# signed_item = item . copy ( ) #NEWLINE# timestamp = time . time ( ) #NEWLINE# expires_at = 0.0 #NEWLINE# t = type ( expires ) #NEWLINE# if ( expires and ( ( t == int ) or ( t == float ) ) and ( expires > 0 ) ) : #NEWLINE# #INDENT# expires_at = ( timestamp + expires ) #NEWLINE# #UNINDENT# signed_item [ '_p4p2p' ] = { #NEWLINE# #INDENT# 'timestamp' : timestamp , #NEWLINE# 'expires' : expires_at , #NEWLINE# 'version' : get_version ( ) , #NEWLINE# 'public_key' : public_key , #NEWLINE# #UNINDENT# } #NEWLINE# root_hash = _get_hash ( signed_item ) #NEWLINE# key = RSA . importKey ( private_key ) #NEWLINE# signer = PKCS1_v1_5 . new ( key ) #NEWLINE# sig = base64 . encodebytes ( signer . sign ( root_hash ) ) . decode ( 'utf-8' ) #NEWLINE# signed_item [ '_p4p2p' ] [ 'signature' ] = sig #NEWLINE# return signed_item