Exemplo n.º 1
0
static wi_string_t * _wi_p7_message_description(wi_runtime_instance_t *instance) {
	wi_p7_message_t			*p7_message = instance;
	wi_enumerator_t			*enumerator;
	wi_dictionary_t			*fields;
	wi_mutable_string_t		*string;
	wi_string_t				*field_name, *field_value;
	
	string = wi_mutable_string_with_format(WI_STR("<%@ %p>{name = %@, buffer = %@, fields = (\n"),
        wi_runtime_class_name(p7_message),
        p7_message,
		p7_message->name,
		wi_data_with_bytes_no_copy(p7_message->binary_buffer, p7_message->binary_size, false));
	
	fields		= wi_p7_message_fields(p7_message);
	enumerator	= wi_dictionary_key_enumerator(fields);
	
	while((field_name = wi_enumerator_next_data(enumerator))) {
		field_value = wi_dictionary_data_for_key(fields, field_name);

		wi_mutable_string_append_format(string, WI_STR("    %@ = %@\n"),
			field_name, field_value);
	}
	
	wi_mutable_string_append_string(string, WI_STR(")}"));
	
	wi_runtime_make_immutable(string);
	
	return string;
}
Exemplo n.º 2
0
wi_data_t * wi_random_data(wi_uinteger_t length) {
    void    *buffer;
    
    buffer = wi_malloc(length);
    
    wi_random_get_bytes(buffer, length);
    
    return wi_data_with_bytes_no_copy(buffer, length, true);
}
Exemplo n.º 3
0
wi_data_t * wi_cipher_decrypt(wi_cipher_t *cipher, wi_data_t *encrypted_data) {
	const void		*encrypted_buffer;
	void			*decrypted_buffer;
	wi_uinteger_t	encrypted_length, decrypted_length;
	
	encrypted_buffer = wi_data_bytes(encrypted_data);
	encrypted_length = wi_data_length(encrypted_data);
	
	if(!wi_cipher_decrypt_bytes(cipher, encrypted_buffer, encrypted_length, &decrypted_buffer, &decrypted_length))
		return NULL;
	
	return wi_data_with_bytes_no_copy(decrypted_buffer, decrypted_length, true);
}
Exemplo n.º 4
0
wi_data_t * wi_rsa_encrypt(wi_rsa_t *rsa, wi_data_t *decrypted_data) {
	const void		*decrypted_buffer;
	void			*encrypted_buffer;
	wi_uinteger_t	decrypted_length, encrypted_length;
	
	decrypted_buffer = wi_data_bytes(decrypted_data);
	decrypted_length = wi_data_length(decrypted_data);
	
	if(!wi_rsa_encrypt_bytes(rsa, decrypted_buffer, decrypted_length, &encrypted_buffer, &encrypted_length))
		return NULL;
	
	return wi_data_with_bytes_no_copy(encrypted_buffer, encrypted_length, true);
}
Exemplo n.º 5
0
wi_data_t * wi_cipher_decrypt(wi_cipher_t *cipher, wi_data_t *encrypted_data) {
	const void		*encrypted_buffer;
	void			*decrypted_buffer;
	wi_uinteger_t	encrypted_length;
	wi_integer_t	decrypted_length;
	
	encrypted_buffer = wi_data_bytes(encrypted_data);
	encrypted_length = wi_data_length(encrypted_data);
	decrypted_buffer = wi_malloc(wi_cipher_block_size(cipher) + encrypted_length);
	decrypted_length = wi_cipher_decrypt_bytes(cipher, encrypted_buffer, encrypted_length, decrypted_buffer);
	
	if(decrypted_length < 0)
		return NULL;
	
	return wi_data_with_bytes_no_copy(decrypted_buffer, decrypted_length, true);
}
Exemplo n.º 6
0
wi_data_t * wi_p7_message_data_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name) {
	wi_string_t		*string;
	unsigned char	*binary;
	uint32_t		field_size;
	
	if(p7_message->serialization == WI_P7_BINARY) {
		if(!_wi_p7_message_get_binary_buffer_for_reading_for_name(p7_message, field_name, &binary, &field_size))
			return NULL;
		
		return wi_data_with_bytes_no_copy(binary, field_size, false);
	} else {
		string = _wi_p7_message_xml_value_for_name(p7_message, field_name);
		
		if(!string)
			return NULL;
		
		return wi_autorelease(wi_data_init_with_base64(wi_data_alloc(), string));
	}
}
Exemplo n.º 7
0
static wi_string_t * _wi_p7_message_description(wi_runtime_instance_t *instance) {
	wi_p7_message_t		*p7_message = instance;
	wi_hash_t			*fields;
	wi_enumerator_t		*enumerator;
	wi_string_t			*description, *xml_string, *field_name;
	
	description = wi_string_init_with_format(wi_string_alloc(), WI_STR("<%@ %p>{name = %@, serialization = %@"),
        wi_runtime_class_name(p7_message),
        p7_message,
		p7_message->name,
		p7_message->serialization == WI_P7_BINARY ? WI_STR("binary") : WI_STR("xml"));
	
	if(p7_message->serialization == WI_P7_BINARY) {
		wi_string_append_format(description, WI_STR(", buffer = %@, fields = (\n"),
			wi_data_with_bytes_no_copy(p7_message->binary_buffer, p7_message->binary_size, false));
	} else {
		if(p7_message->xml_string)
			xml_string = p7_message->xml_string;
		else
			xml_string = wi_string_with_bytes(p7_message->xml_buffer, p7_message->xml_length);
			
		wi_string_append_format(description, WI_STR(", xml = \"%@\", fields = (\n"),
			xml_string);
	}
	
	fields = wi_p7_message_fields(p7_message);
	enumerator = wi_hash_key_enumerator(fields);
	
	while((field_name = wi_enumerator_next_data(enumerator))) {
		wi_string_append_format(description, WI_STR("    %@ = %@\n"),
			field_name, wi_hash_data_for_key(fields, field_name));
	}

	wi_string_append_string(description, WI_STR(")}"));
	
	return wi_autorelease(description);
}