def sign(wire, keyname, secret, time, fudge, original_id, error, other_data, request_mac, ctx=None, multi=False, first=True, algorithm=default_algorithm):
 (algorithm_name, digestmod) = get_algorithm(algorithm)
 if first:
  ctx = hmac.new(secret, digestmod=digestmod)
  ml = len(request_mac)
  if (ml > 0):
   ctx.update(struct.pack('!H', ml))
   ctx.update(request_mac)
 id = struct.pack('!H', original_id)
 ctx.update(id)
 ctx.update(wire[2:])
 if first:
  ctx.update(keyname.to_digestable())
  ctx.update(struct.pack('!H', dns.rdataclass.ANY))
  ctx.update(struct.pack('!I', 0))
 long_time = (time + 0L)
 upper_time = ((long_time >> 32) & 65535L)
 lower_time = (long_time & 4294967295L)
 time_mac = struct.pack('!HIH', upper_time, lower_time, fudge)
 pre_mac = (algorithm_name + time_mac)
 ol = len(other_data)
 if (ol > 65535):
  raise ValueError('TSIG Other Data is > 65535 bytes')
 post_mac = (struct.pack('!HH', error, ol) + other_data)
 if first:
  ctx.update(pre_mac)
  ctx.update(post_mac)
 else:
  ctx.update(time_mac)
 mac = ctx.digest()
 mpack = struct.pack('!H', len(mac))
 tsig_rdata = ((((pre_mac + mpack) + mac) + id) + post_mac)
 if multi:
  ctx = hmac.new(secret, digestmod=digestmod)
  ml = len(mac)
  ctx.update(struct.pack('!H', ml))
  ctx.update(mac)
 else:
  ctx = None
 return (tsig_rdata, mac, ctx)

def sign ( wire , keyname , secret , time , fudge , original_id , error , other_data , request_mac , ctx = None , multi = False , first = True , algorithm = default_algorithm ) : ( algorithm_name , digestmod ) = get_algorithm ( algorithm ) if first : ctx = hmac . new ( secret , digestmod = digestmod ) ml = len ( request_mac ) if ( ml > 0 ) : ctx . update ( struct . pack ( '!H' , ml ) ) ctx . update ( request_mac ) id = struct . pack ( '!H' , original_id ) ctx . update ( id ) ctx . update ( wire [ 2 : ] ) if first : ctx . update ( keyname . to_digestable ( ) ) ctx . update ( struct . pack ( '!H' , dns . rdataclass . ANY ) ) ctx . update ( struct . pack ( '!I' , 0 ) ) long_time = ( time + 0 L ) upper_time = ( ( long_time >> 32 ) & 65535 L ) lower_time = ( long_time & 4294967295 L ) time_mac = struct . pack ( '!HIH' , upper_time , lower_time , fudge ) pre_mac = ( algorithm_name + time_mac ) ol = len ( other_data ) if ( ol > 65535 ) : raise ValueError ( 'TSIG Other Data is > 65535 bytes' ) post_mac = ( struct . pack ( '!HH' , error , ol ) + other_data ) if first : ctx . update ( pre_mac ) ctx . update ( post_mac ) else : ctx . update ( time_mac ) mac = ctx . digest ( ) mpack = struct . pack ( '!H' , len ( mac ) ) tsig_rdata = ( ( ( ( pre_mac + mpack ) + mac ) + id ) + post_mac ) if multi : ctx = hmac . new ( secret , digestmod = digestmod ) ml = len ( mac ) ctx . update ( struct . pack ( '!H' , ml ) ) ctx . update ( mac ) else : ctx = None return ( tsig_rdata , mac , ctx )
returns a signed receipt .