byte[] private_key = subs.getPrivateKey();
if ( private_key == null ){
throw( new SubscriptionException( "Only the originator of a subscription can modify it" ));
}
map.put( "size", new Long( contents.length ));
try{
map.put( "hash", new_hash );
map.put( "sig", sign( private_key, new_hash, version, contents.length ));
}catch( Throwable e ){
throw( new SubscriptionException( "Crypto failed: " + Debug.getNestedExceptionMessage(e)));
}
}
File backup_file = null;
if ( file.exists()){
backup_file = new File( file.getParent(), file.getName() + ".bak" );
backup_file.delete();
if ( !file.renameTo( backup_file )){
throw( new SubscriptionException( "Backup failed" ));
}
}
try{
VuzeFile vf = VuzeFileHandler.getSingleton().create();
vf.addComponent( VuzeFileComponent.COMP_TYPE_SUBSCRIPTION, map );
vf.write( file );
hash = new_hash;
sig = (byte[])map.get( "sig" );
sig_data_size = contents.length;
}catch( Throwable e ){
if ( backup_file != null ){
backup_file.renameTo( file );
}
throw( new SubscriptionException( "File write failed: " + Debug.getNestedExceptionMessage(e)));
}
}catch( Throwable e ){
rethrow( e );
}