Exemplo n.º 1
0
void Init_gsl_integration(VALUE module)
{
  VALUE mgsl_integ;

  mgsl_integ = rb_define_module_under(module, "Integration");
  rb_gsl_integration_define_symbols(mgsl_integ);

  rb_define_method(cgsl_function, "integration_qng", rb_gsl_integration_qng, -1);
  rb_define_method(cgsl_function, "integration_qag", rb_gsl_integration_qag, -1);
  rb_define_method(cgsl_function, "integration_qags", rb_gsl_integration_qags, -1);
  rb_define_method(cgsl_function, "integration_qagp", rb_gsl_integration_qagp, -1);
  rb_define_method(cgsl_function, "integration_qagi", rb_gsl_integration_qagi, -1);
  rb_define_method(cgsl_function, "integration_qagiu", rb_gsl_integration_qagiu, -1);
  rb_define_method(cgsl_function, "integration_qagil", rb_gsl_integration_qagil, -1);
  rb_define_method(cgsl_function, "integration_qawc", rb_gsl_integration_qawc, -1);
  rb_define_alias(cgsl_function, "qng", "integration_qng");
  rb_define_alias(cgsl_function, "qag", "integration_qag");
  rb_define_alias(cgsl_function, "qags", "integration_qags");
  rb_define_alias(cgsl_function, "qagp", "integration_qagp");
  rb_define_alias(cgsl_function, "qagi", "integration_qagi");
  rb_define_alias(cgsl_function, "qagiu", "integration_qagiu");
  rb_define_alias(cgsl_function, "qagil", "integration_qagil");
  rb_define_alias(cgsl_function, "qawc", "integration_qawc");

  cgsl_integration_qaws_table = rb_define_class_under(mgsl_integ, "QAWS_Table", 
						      cGSL_Object);
  rb_define_singleton_method(cgsl_integration_qaws_table, "alloc",
			     rb_gsl_integration_qaws_table_alloc, -1);
  /*  rb_define_singleton_method(cgsl_integration_qaws_table, "new",
      rb_gsl_integration_qaws_table_alloc, -1);*/
  rb_define_method(cgsl_integration_qaws_table, "to_a", 
		   rb_gsl_integration_qaws_table_to_a, 0);
  rb_define_method(cgsl_integration_qaws_table, "set", 
		   rb_gsl_integration_qaws_table_set, -1);
  rb_define_method(rb_cArray, "to_gsl_integration_qaws_table", 
		   rb_gsl_ary_to_integration_qaws_table, 0);
  rb_define_alias(rb_cArray, "to_qaws_table", "to_gsl_integration_qaws_table");
  rb_define_method(cgsl_function, "integration_qaws", rb_gsl_integration_qaws, -1);
  rb_define_alias(cgsl_function, "qaws", "integration_qaws");

  cgsl_integration_qawo_table = rb_define_class_under(mgsl_integ, "QAWO_Table", 
						      cGSL_Object);
  rb_define_singleton_method(cgsl_integration_qawo_table, "alloc",
			     rb_gsl_integration_qawo_table_alloc, -1);
  /*  rb_define_singleton_method(cgsl_integration_qawo_table, "new",
      rb_gsl_integration_qawo_table_alloc, -1);*/
  rb_define_method(cgsl_integration_qawo_table, "to_a", 
		   rb_gsl_integration_qawo_table_to_a, 0);
  rb_define_method(rb_cArray, "to_gsl_integration_qawo_table", 
		   rb_gsl_ary_to_integration_qawo_table, 0);
  rb_define_method(cgsl_integration_qawo_table, "set", 
		   rb_gsl_integration_qawo_table_set, -1);
  rb_define_method(cgsl_integration_qawo_table, "set_length", 
		   rb_gsl_integration_qawo_table_set_length, 1);
  rb_define_method(cgsl_function, "integration_qawo", rb_gsl_integration_qawo, -1);
  rb_define_method(cgsl_function, "integration_qawf", rb_gsl_integration_qawf, -1);
  rb_define_alias(cgsl_function, "qawo", "integration_qawo");
  rb_define_alias(cgsl_function, "qawf", "integration_qawf");

  cgsl_integration_workspace = rb_define_class_under(mgsl_integ, 
						     "Workspace", cGSL_Object);

  /*  rb_define_singleton_method(cgsl_integration_workspace, "new",
      rb_gsl_integration_workspace_alloc, -1);*/
  rb_define_singleton_method(cgsl_integration_workspace, "alloc",
			     rb_gsl_integration_workspace_alloc, -1);

  rb_define_method(cgsl_integration_workspace, "limit", 
		   rb_gsl_integration_workspace_limit, 0);
  rb_define_method(cgsl_integration_workspace, "size", 
		   rb_gsl_integration_workspace_size, 0);
  rb_define_method(cgsl_integration_workspace, "nrmax", 
		   rb_gsl_integration_workspace_nrmax, 0);
  rb_define_method(cgsl_integration_workspace, "i", 
		   rb_gsl_integration_workspace_i, 0);
  rb_define_method(cgsl_integration_workspace, "maximum_level", 
		   rb_gsl_integration_workspace_maximum_level, 0);
  rb_define_method(cgsl_integration_workspace, "to_a", 
		   rb_gsl_integration_workspace_to_a, 0);
  rb_define_method(cgsl_integration_workspace, "alist", 
		   rb_gsl_integration_workspace_alist, 0);
  rb_define_method(cgsl_integration_workspace, "blist", 
		   rb_gsl_integration_workspace_blist, 0);
  rb_define_method(cgsl_integration_workspace, "rlist", 
		   rb_gsl_integration_workspace_rlist, 0);
  rb_define_method(cgsl_integration_workspace, "elist", 
		   rb_gsl_integration_workspace_elist, 0);

  /*****/
  rb_define_module_function(mgsl_integ, "qng", rb_gsl_integration_qng, -1);
  rb_define_module_function(mgsl_integ, "qag", rb_gsl_integration_qag, -1);
  rb_define_module_function(mgsl_integ, "qags", rb_gsl_integration_qags, -1);
  rb_define_module_function(mgsl_integ, "qagp", rb_gsl_integration_qagp, -1);
  rb_define_module_function(mgsl_integ, "qagi", rb_gsl_integration_qagi, -1);
  rb_define_module_function(mgsl_integ, "qagiu", rb_gsl_integration_qagiu, -1);
  rb_define_module_function(mgsl_integ, "qagil", rb_gsl_integration_qagil, -1);
  rb_define_module_function(mgsl_integ, "qawc", rb_gsl_integration_qawc, -1);
  rb_define_module_function(mgsl_integ, "qaws", rb_gsl_integration_qaws, -1);
  rb_define_module_function(mgsl_integ, "qawo", rb_gsl_integration_qawo, -1);
  rb_define_module_function(mgsl_integ, "qawf", rb_gsl_integration_qawf, -1);
}
Exemplo n.º 2
0
void
Init_shadow()
{
  rb_sPasswdEntry = rb_struct_define("PasswdEntry",
				     "sp_namp","sp_pwdp","sp_lstchg",
				     "sp_min","sp_max","sp_warn",
				     "sp_inact","sp_expire","sp_flag",0);
  rb_sGroupEntry = rb_struct_define("GroupEntry",
				    "sg_name","sg_passwd",
				    "sg_adm","sg_mem",0);

  rb_mShadow = rb_define_module("Shadow");
  rb_eFileLock = rb_define_class_under(rb_mShadow,"FileLock",rb_eException);
  rb_mPasswd = rb_define_module_under(rb_mShadow,"Passwd");
  rb_define_const(rb_mPasswd,"Entry",rb_sPasswdEntry);
  rb_mGroup = rb_define_module_under(rb_mShadow,"Group");
  rb_define_const(rb_mGroup,"Entry",rb_sGroupEntry);

  rb_define_module_function(rb_mPasswd,"setspent",rb_shadow_setspent,0);
  rb_define_module_function(rb_mPasswd,"endspent",rb_shadow_endspent,0);
#ifndef SOLARIS
  rb_define_module_function(rb_mPasswd,"sgetspent",rb_shadow_sgetspent,1);
#endif
  rb_define_module_function(rb_mPasswd,"fgetspent",rb_shadow_fgetspent,1);
  rb_define_module_function(rb_mPasswd,"getspent",rb_shadow_getspent,0);
  rb_define_module_function(rb_mPasswd,"getspnam",rb_shadow_getspnam,1);
  rb_define_module_function(rb_mPasswd,"putspent",rb_shadow_putspent,2);
  rb_define_module_function(rb_mPasswd,"lckpwdf",rb_shadow_lckpwdf,0);
  rb_define_module_function(rb_mPasswd,"lock",rb_shadow_lock,0);
  rb_define_module_function(rb_mPasswd,"ulckpwdf",rb_shadow_ulckpwdf,0);
  rb_define_module_function(rb_mPasswd,"unlock",rb_shadow_unlock,0);
  rb_define_module_function(rb_mPasswd,"lock?",rb_shadow_lock_p,0);
};
Exemplo n.º 3
0
/*
 * Some functions to put data to the network with high performance.
 */
void Init_io2io_c()
{
	M_io2io= rb_define_module("IO2IO");
	rb_define_module_function(M_io2io, "do_c", t_do, 3);
}
Exemplo n.º 4
0
extern "C" void Init_rubyeventmachine()
{
	// Lookup Process::Status for get_subprocess_status
	VALUE rb_mProcess = rb_const_get(rb_cObject, rb_intern("Process"));
	rb_cProcStatus = rb_const_get(rb_mProcess, rb_intern("Status"));

	// Tuck away some symbol values so we don't have to look 'em up every time we need 'em.
	Intern_at_signature = rb_intern ("@signature");
	Intern_at_timers = rb_intern ("@timers");
	Intern_at_conns = rb_intern ("@conns");
	Intern_at_error_handler = rb_intern("@error_handler");

	Intern_event_callback = rb_intern ("event_callback");
	Intern_run_deferred_callbacks = rb_intern ("run_deferred_callbacks");
	Intern_delete = rb_intern ("delete");
	Intern_call = rb_intern ("call");
	Intern_receive_data = rb_intern ("receive_data");
	Intern_ssl_handshake_completed = rb_intern ("ssl_handshake_completed");
	Intern_ssl_verify_peer = rb_intern ("ssl_verify_peer");
	Intern_notify_readable = rb_intern ("notify_readable");
	Intern_notify_writable = rb_intern ("notify_writable");
	Intern_proxy_target_unbound = rb_intern ("proxy_target_unbound");
	Intern_proxy_completed = rb_intern ("proxy_completed");
	Intern_connection_completed = rb_intern ("connection_completed");

	// INCOMPLETE, we need to define class Connections inside module EventMachine
	// run_machine and run_machine_without_threads are now identical.
	// Must deprecate the without_threads variant.
	EmModule = rb_define_module ("EventMachine");
	EmConnection = rb_define_class_under (EmModule, "Connection", rb_cObject);

	rb_define_class_under (EmModule, "NoHandlerForAcceptedConnection", rb_eRuntimeError);
	EM_eConnectionError = rb_define_class_under (EmModule, "ConnectionError", rb_eRuntimeError);
	EM_eConnectionNotBound = rb_define_class_under (EmModule, "ConnectionNotBound", rb_eRuntimeError);
	EM_eUnknownTimerFired = rb_define_class_under (EmModule, "UnknownTimerFired", rb_eRuntimeError);
	EM_eUnsupported = rb_define_class_under (EmModule, "Unsupported", rb_eRuntimeError);

	rb_define_module_function (EmModule, "initialize_event_machine", (VALUE(*)(...))t_initialize_event_machine, 0);
	rb_define_module_function (EmModule, "run_machine", (VALUE(*)(...))t_run_machine_without_threads, 0);
	rb_define_module_function (EmModule, "run_machine_without_threads", (VALUE(*)(...))t_run_machine_without_threads, 0);
	rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1);
	rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2);
	rb_define_module_function (EmModule, "stop_tcp_server", (VALUE(*)(...))t_stop_server, 1);
	rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1);
	rb_define_module_function (EmModule, "set_tls_parms", (VALUE(*)(...))t_set_tls_parms, 6);
	rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1);
	rb_define_module_function (EmModule, "get_peer_cert", (VALUE(*)(...))t_get_peer_cert, 1);
	rb_define_module_function (EmModule, "send_data", (VALUE(*)(...))t_send_data, 3);
	rb_define_module_function (EmModule, "send_datagram", (VALUE(*)(...))t_send_datagram, 5);
	rb_define_module_function (EmModule, "close_connection", (VALUE(*)(...))t_close_connection, 2);
	rb_define_module_function (EmModule, "report_connection_error_status", (VALUE(*)(...))t_report_connection_error_status, 1);
	rb_define_module_function (EmModule, "connect_server", (VALUE(*)(...))t_connect_server, 2);
	rb_define_module_function (EmModule, "bind_connect_server", (VALUE(*)(...))t_bind_connect_server, 4);
	rb_define_module_function (EmModule, "connect_unix_server", (VALUE(*)(...))t_connect_unix_server, 1);

	rb_define_module_function (EmModule, "attach_fd", (VALUE (*)(...))t_attach_fd, 2);
	rb_define_module_function (EmModule, "detach_fd", (VALUE (*)(...))t_detach_fd, 1);
	rb_define_module_function (EmModule, "get_sock_opt", (VALUE (*)(...))t_get_sock_opt, 3);
	rb_define_module_function (EmModule, "set_sock_opt", (VALUE (*)(...))t_set_sock_opt, 4);
	rb_define_module_function (EmModule, "set_notify_readable", (VALUE (*)(...))t_set_notify_readable, 2);
	rb_define_module_function (EmModule, "set_notify_writable", (VALUE (*)(...))t_set_notify_writable, 2);
	rb_define_module_function (EmModule, "is_notify_readable", (VALUE (*)(...))t_is_notify_readable, 1);
	rb_define_module_function (EmModule, "is_notify_writable", (VALUE (*)(...))t_is_notify_writable, 1);

	rb_define_module_function (EmModule, "pause_connection", (VALUE (*)(...))t_pause, 1);
	rb_define_module_function (EmModule, "resume_connection", (VALUE (*)(...))t_resume, 1);
	rb_define_module_function (EmModule, "connection_paused?", (VALUE (*)(...))t_paused_p, 1);
	rb_define_module_function (EmModule, "num_close_scheduled", (VALUE (*)(...))t_num_close_scheduled, 0);

	rb_define_module_function (EmModule, "start_proxy", (VALUE (*)(...))t_start_proxy, 4);
	rb_define_module_function (EmModule, "stop_proxy", (VALUE (*)(...))t_stop_proxy, 1);
	rb_define_module_function (EmModule, "get_proxied_bytes", (VALUE (*)(...))t_proxied_bytes, 1);

	rb_define_module_function (EmModule, "watch_filename", (VALUE (*)(...))t_watch_filename, 1);
	rb_define_module_function (EmModule, "unwatch_filename", (VALUE (*)(...))t_unwatch_filename, 1);

	rb_define_module_function (EmModule, "watch_pid", (VALUE (*)(...))t_watch_pid, 1);
	rb_define_module_function (EmModule, "unwatch_pid", (VALUE (*)(...))t_unwatch_pid, 1);

	rb_define_module_function (EmModule, "current_time", (VALUE(*)(...))t_get_loop_time, 0);

	rb_define_module_function (EmModule, "open_udp_socket", (VALUE(*)(...))t_open_udp_socket, 2);
	rb_define_module_function (EmModule, "read_keyboard", (VALUE(*)(...))t_read_keyboard, 0);
	rb_define_module_function (EmModule, "release_machine", (VALUE(*)(...))t_release_machine, 0);
	rb_define_module_function (EmModule, "stop", (VALUE(*)(...))t_stop, 0);
	rb_define_module_function (EmModule, "signal_loopbreak", (VALUE(*)(...))t_signal_loopbreak, 0);
	rb_define_module_function (EmModule, "library_type", (VALUE(*)(...))t_library_type, 0);
	rb_define_module_function (EmModule, "set_timer_quantum", (VALUE(*)(...))t_set_timer_quantum, 1);
	rb_define_module_function (EmModule, "get_max_timer_count", (VALUE(*)(...))t_get_max_timer_count, 0);
	rb_define_module_function (EmModule, "set_max_timer_count", (VALUE(*)(...))t_set_max_timer_count, 1);
	rb_define_module_function (EmModule, "setuid_string", (VALUE(*)(...))t_setuid_string, 1);
	rb_define_module_function (EmModule, "invoke_popen", (VALUE(*)(...))t_invoke_popen, 1);
	rb_define_module_function (EmModule, "send_file_data", (VALUE(*)(...))t_send_file_data, 2);
	rb_define_module_function (EmModule, "get_heartbeat_interval", (VALUE(*)(...))t_get_heartbeat_interval, 0);
	rb_define_module_function (EmModule, "set_heartbeat_interval", (VALUE(*)(...))t_set_heartbeat_interval, 1);
	rb_define_module_function (EmModule, "get_idle_time", (VALUE(*)(...))t_get_idle_time, 1);

	rb_define_module_function (EmModule, "get_peername", (VALUE(*)(...))t_get_peername, 1);
	rb_define_module_function (EmModule, "get_sockname", (VALUE(*)(...))t_get_sockname, 1);
	rb_define_module_function (EmModule, "get_subprocess_pid", (VALUE(*)(...))t_get_subprocess_pid, 1);
	rb_define_module_function (EmModule, "get_subprocess_status", (VALUE(*)(...))t_get_subprocess_status, 1);
	rb_define_module_function (EmModule, "get_comm_inactivity_timeout", (VALUE(*)(...))t_get_comm_inactivity_timeout, 1);
	rb_define_module_function (EmModule, "set_comm_inactivity_timeout", (VALUE(*)(...))t_set_comm_inactivity_timeout, 2);
	rb_define_module_function (EmModule, "get_pending_connect_timeout", (VALUE(*)(...))t_get_pending_connect_timeout, 1);
	rb_define_module_function (EmModule, "set_pending_connect_timeout", (VALUE(*)(...))t_set_pending_connect_timeout, 2);
	rb_define_module_function (EmModule, "set_rlimit_nofile", (VALUE(*)(...))t_set_rlimit_nofile, 1);
	rb_define_module_function (EmModule, "get_connection_count", (VALUE(*)(...))t_get_connection_count, 0);

	rb_define_module_function (EmModule, "epoll", (VALUE(*)(...))t__epoll, 0);
	rb_define_module_function (EmModule, "epoll=", (VALUE(*)(...))t__epoll_set, 1);
	rb_define_module_function (EmModule, "epoll?", (VALUE(*)(...))t__epoll_p, 0);

	rb_define_module_function (EmModule, "kqueue", (VALUE(*)(...))t__kqueue, 0);
	rb_define_module_function (EmModule, "kqueue=", (VALUE(*)(...))t__kqueue_set, 1);
	rb_define_module_function (EmModule, "kqueue?", (VALUE(*)(...))t__kqueue_p, 0);

	rb_define_module_function (EmModule, "ssl?", (VALUE(*)(...))t__ssl_p, 0);

	rb_define_method (EmConnection, "get_outbound_data_size", (VALUE(*)(...))conn_get_outbound_data_size, 0);
	rb_define_method (EmConnection, "associate_callback_target", (VALUE(*)(...))conn_associate_callback_target, 1);

	rb_define_const (EmModule, "TimerFired", INT2NUM(100));
	rb_define_const (EmModule, "ConnectionData", INT2NUM(101));
	rb_define_const (EmModule, "ConnectionUnbound", INT2NUM(102));
	rb_define_const (EmModule, "ConnectionAccepted", INT2NUM(103));
	rb_define_const (EmModule, "ConnectionCompleted", INT2NUM(104));
	rb_define_const (EmModule, "LoopbreakSignalled", INT2NUM(105));

	rb_define_const (EmModule, "ConnectionNotifyReadable", INT2NUM(106));
	rb_define_const (EmModule, "ConnectionNotifyWritable", INT2NUM(107));

	rb_define_const (EmModule, "SslHandshakeCompleted", INT2NUM(108));

}
Exemplo n.º 5
0
void Init_gsl_sf_gamma(VALUE module)
{
  rb_define_const(module, "GAMMA_XMAX", NUM2DBL(GSL_SF_GAMMA_XMAX));
  rb_define_module_function(module, "gamma",  rb_gsl_sf_gamma, 1);
  rb_define_module_function(module, "gamma_e",  rb_gsl_sf_gamma_e, 1);
  rb_define_module_function(module, "lngamma",  rb_gsl_sf_lngamma, 1);
  rb_define_module_function(module, "lngamma_e",  rb_gsl_sf_lngamma_e, 1);
  rb_define_module_function(module, "lngamma_sgn_e",  rb_gsl_sf_lngamma_sgn_e, 1);
  rb_define_module_function(module, "gammastar",  rb_gsl_sf_gammastar, 1);
  rb_define_module_function(module, "gammastar_e",  rb_gsl_sf_gammastar_e, 1);
  rb_define_module_function(module, "gammainv",  rb_gsl_sf_gammainv, 1);
  rb_define_module_function(module, "gammainv_e",  rb_gsl_sf_gammainv_e, 1);
  rb_define_module_function(module, "lngamma_complex_e",  rb_gsl_sf_lngamma_complex_e, -1);
  rb_define_module_function(module, "taylorcoeff",  rb_gsl_sf_taylorcoeff, 2);
  rb_define_module_function(module, "taylorcoeff_e",  rb_gsl_sf_taylorcoeff_e, 2);
  rb_define_module_function(module, "fact",  rb_gsl_sf_fact, 1);
  rb_define_module_function(module, "fact_e",  rb_gsl_sf_fact_e, 1);
  rb_define_module_function(module, "doublefact",  rb_gsl_sf_doublefact, 1);
  rb_define_module_function(module, "doublefact_e",  rb_gsl_sf_doublefact_e, 1);
  rb_define_module_function(module, "lnfact",  rb_gsl_sf_lnfact, 1);
  rb_define_module_function(module, "lnfact_e",  rb_gsl_sf_lnfact_e, 1);
  rb_define_module_function(module, "lndoublefact",  rb_gsl_sf_lndoublefact, 1);
  rb_define_module_function(module, "lndoublefact_e",  rb_gsl_sf_lndoublefact_e, 1);
  rb_define_module_function(module, "choose",  rb_gsl_sf_choose, 2);
  rb_define_module_function(module, "choose_e",  rb_gsl_sf_choose_e, 2);
  rb_define_module_function(module, "lnchoose",  rb_gsl_sf_lnchoose, 2);
  rb_define_module_function(module, "lnchoose_e",  rb_gsl_sf_lnchoose_e, 2);
  rb_define_module_function(module, "poch",  rb_gsl_sf_poch, 2);
  rb_define_module_function(module, "poch_e",  rb_gsl_sf_poch_e, 2);
  rb_define_module_function(module, "lnpoch",  rb_gsl_sf_lnpoch, 2);
  rb_define_module_function(module, "lnpoch_e",  rb_gsl_sf_lnpoch_e, 2);
  rb_define_module_function(module, "lnpoch_sgn_e",  rb_gsl_sf_lnpoch_sgn_e, 2);
  rb_define_module_function(module, "pochrel",  rb_gsl_sf_pochrel, 2);
  rb_define_module_function(module, "pochrel_e",  rb_gsl_sf_pochrel_e, 2);
  rb_define_module_function(module, "gamma_inc_P",  rb_gsl_sf_gamma_inc_P, 2);
  rb_define_module_function(module, "gamma_inc_P_e",  rb_gsl_sf_gamma_inc_P_e, 2);
  rb_define_module_function(module, "gamma_inc_Q",  rb_gsl_sf_gamma_inc_Q, 2);
  rb_define_module_function(module, "gamma_inc_Q_e",  rb_gsl_sf_gamma_inc_Q_e, 2);
  rb_define_module_function(module, "gamma_inc",  rb_gsl_sf_gamma_inc, 2);

#ifdef GSL_1_4_LATER
  rb_define_module_function(module, "gamma_inc_e",  rb_gsl_sf_gamma_inc_e, 2);
#endif
  rb_define_module_function(module, "beta",  rb_gsl_sf_beta, 2);
  rb_define_module_function(module, "beta_e",  rb_gsl_sf_beta_e, 2);
  rb_define_module_function(module, "lnbeta",  rb_gsl_sf_lnbeta, 2);
  rb_define_module_function(module, "lnbeta_e",  rb_gsl_sf_lnbeta_e, 2);
  rb_define_module_function(module, "beta_inc",  rb_gsl_sf_beta_inc, 3);
  rb_define_module_function(module, "beta_inc_e",  rb_gsl_sf_beta_inc_e, 3);

  rb_define_module_function(module, "bincoef",  rb_gsl_sf_bincoef, 2);
}
Exemplo n.º 6
0
void Init_usbbasics() {
  module = rb_define_module("USB");
  cException = rb_define_class_under(module, "UsbException", rb_eStandardError);
  cDevice = rb_define_class_under(module, "Device", rb_cObject);
  rb_define_module_function(module, "load_devices", load_devices, 0);

  rb_define_method(cDevice, "filename", device_filename, 0);
  rb_define_method(cDevice, "dirname", device_dirname, 0);
  rb_define_method(cDevice, "device_num", device_device_num, 0);
  rb_define_method(cDevice, "location", device_location, 0);
  rb_define_method(cDevice, "children", device_children, 0);
  rb_define_method(cDevice, "usb_version", device_usb_version, 0);
  rb_define_method(cDevice, "device_version", device_device_version, 0);
  rb_define_method(cDevice, "vendor_id", device_vendor_id, 0);
  rb_define_method(cDevice, "product_id", device_product_id, 0);
  rb_define_method(cDevice, "device_class", device_device_class, 0);
  rb_define_method(cDevice, "device_subclass", device_device_subclass, 0);
  rb_define_method(cDevice, "device_protocol", device_device_protocol, 0);
  rb_define_method(cDevice, "product_name", device_product_name, 0);
  rb_define_method(cDevice, "manufacturer", device_manufacturer, 0);
  rb_define_method(cDevice, "serial_number", device_serial_number, 0);
  rb_define_method(cDevice, "max_packet_size_for_endpoint_0", device_max_packet_size_for_endpoint_0, 0);
  rb_define_method(cDevice, "load_configurations", device_configurations, 0);
  rb_define_method(cDevice, "current_configuration_value", device_current_configuration_value, 0);
  rb_define_method(cDevice, "open?", device_is_open, 0);
  rb_define_method(cDevice, "open", device_open, 0);
  rb_define_method(cDevice, "close", device_close, 0);
  cEndpoint = rb_define_class_under(module, "Endpoint", rb_cObject);
  rb_define_method(cEndpoint, "type", endpoint_type, 0);
  rb_define_method(cEndpoint, "output?", endpoint_is_output, 0);
  rb_define_method(cEndpoint, "input?", endpoint_is_input, 0);
  rb_define_method(cEndpoint, "number", endpoint_number, 0);
  rb_define_method(cEndpoint, "max_packet_size", endpoint_max_packet_size, 0);
  rb_define_method(cEndpoint, "interval", endpoint_interval, 0);
  rb_define_method(cEndpoint, "start_interrupt_listening", endpoint_start_listening, 0);
  rb_define_method(cEndpoint, "stop_interrupt_listening", endpoint_stop_listening, 0);
  rb_define_method(cEndpoint, "next_interrupt_or_nil", endpoint_next_interrupt_or_nil, 0);
  cInterface = rb_define_class_under(module, "Interface", rb_cObject);
  rb_define_method(cInterface, "load_endpoints", interface_endpoints, 0);
  rb_define_method(cInterface, "interface_class", interface_interface_class, 0);
  rb_define_method(cInterface, "current_alternative", interface_current_alternative, 0);
  rb_define_method(cInterface, "interface_string", interface_interface_string, 0);
  rb_define_method(cInterface, "subclass", interface_subclass, 0);
  rb_define_method(cInterface, "protocol", interface_protocol, 0);
  rb_define_method(cInterface, "alternate_setting", interface_alternate_setting, 0);
  rb_define_method(cInterface, "number", interface_number, 0);
  rb_define_method(cInterface, "claimable?", interface_is_claimable, 0);
  rb_define_method(cInterface, "detach_kernel", interface_detach_kernel, 0);
  cConfiguration = rb_define_class_under(module, "Configuration", rb_cObject);
  rb_define_method(cConfiguration, "load_interfaces", configuration_interfaces, 0);
  rb_define_method(cConfiguration, "value", configuration_value, 0);
  rb_define_method(cConfiguration, "self_powered?", configuration_is_self_powered, 0);
  rb_define_method(cConfiguration, "remote_wakeup?", configuration_supports_remote_wakeup, 0);
  rb_define_method(cConfiguration, "max_power", configuration_max_power, 0);

  MACRO_MAP_CLASS(cDevice);
  NEW_MACRO_MAP(cDevice, "class_codes");
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_PER_INTERFACE);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_AUDIO);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_COMM);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_HID);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_PRINTER);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_PTP);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_MASS_STORAGE);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_HUB);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_DATA);
  ADD_MACRO_MAPPING(cDevice, "class_codes", USB_CLASS_VENDOR_SPEC);

  NEW_MACRO_MAP(cDevice, "endpoint_types");
  ADD_MACRO_MAPPING(cDevice, "endpoint_types", USB_ENDPOINT_TYPE_CONTROL);
  ADD_MACRO_MAPPING(cDevice, "endpoint_types", USB_ENDPOINT_TYPE_ISOCHRONOUS);
  ADD_MACRO_MAPPING(cDevice, "endpoint_types", USB_ENDPOINT_TYPE_BULK);
  ADD_MACRO_MAPPING(cDevice, "endpoint_types", USB_ENDPOINT_TYPE_INTERRUPT);
  
  usb_init();
}
Exemplo n.º 7
0
void Init_tag_parser()
{ 
	TagParser = rb_define_module("TagParser");
	rb_define_module_function(TagParser, "parse_tags", parse_tags, 3);
}
Exemplo n.º 8
0
/*
 * INIT
 */
void
Init_ossl_cipher(void)
{
#if 0
    mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
#endif

    /* Document-class: OpenSSL::Cipher
     *
     * Provides symmetric algorithms for encryption and decryption. The
     * algorithms that are available depend on the particular version
     * of OpenSSL that is installed.
     *
     * === Listing all supported algorithms
     *
     * A list of supported algorithms can be obtained by
     *
     *   puts OpenSSL::Cipher.ciphers
     *
     * === Instantiating a Cipher
     *
     * There are several ways to create a Cipher instance. Generally, a
     * Cipher algorithm is categorized by its name, the key length in bits
     * and the cipher mode to be used. The most generic way to create a
     * Cipher is the following
     *
     *   cipher = OpenSSL::Cipher.new('<name>-<key length>-<mode>')
     *
     * That is, a string consisting of the hyphenated concatenation of the
     * individual components name, key length and mode. Either all uppercase
     * or all lowercase strings may be used, for example:
     *
     *  cipher = OpenSSL::Cipher.new('AES-128-CBC')
     *
     * For each algorithm supported, there is a class defined under the
     * Cipher class that goes by the name of the cipher, e.g. to obtain an
     * instance of AES, you could also use
     *
     *   # these are equivalent
     *   cipher = OpenSSL::Cipher::AES.new(128, :CBC)
     *   cipher = OpenSSL::Cipher::AES.new(128, 'CBC')
     *   cipher = OpenSSL::Cipher::AES.new('128-CBC')
     *
     * Finally, due to its wide-spread use, there are also extra classes
     * defined for the different key sizes of AES
     *
     *   cipher = OpenSSL::Cipher::AES128.new(:CBC)
     *   cipher = OpenSSL::Cipher::AES192.new(:CBC)
     *   cipher = OpenSSL::Cipher::AES256.new(:CBC)
     *
     * === Choosing either encryption or decryption mode
     *
     * Encryption and decryption are often very similar operations for
     * symmetric algorithms, this is reflected by not having to choose
     * different classes for either operation, both can be done using the
     * same class. Still, after obtaining a Cipher instance, we need to
     * tell the instance what it is that we intend to do with it, so we
     * need to call either
     *
     *   cipher.encrypt
     *
     * or
     *
     *   cipher.decrypt
     *
     * on the Cipher instance. This should be the first call after creating
     * the instance, otherwise configuration that has already been set could
     * get lost in the process.
     *
     * === Choosing a key
     *
     * Symmetric encryption requires a key that is the same for the encrypting
     * and for the decrypting party and after initial key establishment should
     * be kept as private information. There are a lot of ways to create
     * insecure keys, the most notable is to simply take a password as the key
     * without processing the password further. A simple and secure way to
     * create a key for a particular Cipher is
     *
     *  cipher = OpenSSL::AES256.new(:CFB)
     *  cipher.encrypt
     *  key = cipher.random_key # also sets the generated key on the Cipher
     *
     * If you absolutely need to use passwords as encryption keys, you
     * should use Password-Based Key Derivation Function 2 (PBKDF2) by
     * generating the key with the help of the functionality provided by
     * OpenSSL::PKCS5.pbkdf2_hmac_sha1 or OpenSSL::PKCS5.pbkdf2_hmac.
     *
     * Although there is Cipher#pkcs5_keyivgen, its use is deprecated and
     * it should only be used in legacy applications because it does not use
     * the newer PKCS#5 v2 algorithms.
     *
     * === Choosing an IV
     *
     * The cipher modes CBC, CFB, OFB and CTR all need an "initialization
     * vector", or short, IV. ECB mode is the only mode that does not require
     * an IV, but there is almost no legitimate use case for this mode
     * because of the fact that it does not sufficiently hide plaintext
     * patterns. Therefore
     *
     * <b>You should never use ECB mode unless you are absolutely sure that
     * you absolutely need it</b>
     *
     * Because of this, you will end up with a mode that explicitly requires
     * an IV in any case. Note that for backwards compatibility reasons,
     * setting an IV is not explicitly mandated by the Cipher API. If not
     * set, OpenSSL itself defaults to an all-zeroes IV ("\\0", not the
     * character). Although the IV can be seen as public information, i.e.
     * it may be transmitted in public once generated, it should still stay
     * unpredictable to prevent certain kinds of attacks. Therefore, ideally
     *
     * <b>Always create a secure random IV for every encryption of your
     * Cipher</b>
     *
     * A new, random IV should be created for every encryption of data. Think
     * of the IV as a nonce (number used once) - it's public but random and
     * unpredictable. A secure random IV can be created as follows
     *
     *  cipher = ...
     *  cipher.encrypt
     *  key = cipher.random_key
     *  iv = cipher.random_iv # also sets the generated IV on the Cipher
     *
     *  Although the key is generally a random value, too, it is a bad choice
     *  as an IV. There are elaborate ways how an attacker can take advantage
     *  of such an IV. As a general rule of thumb, exposing the key directly
     *  or indirectly should be avoided at all cost and exceptions only be
     *  made with good reason.
     *
     * === Calling Cipher#final
     *
     * ECB (which should not be used) and CBC are both block-based modes.
     * This means that unlike for the other streaming-based modes, they
     * operate on fixed-size blocks of data, and therefore they require a
     * "finalization" step to produce or correctly decrypt the last block of
     * data by appropriately handling some form of padding. Therefore it is
     * essential to add the output of OpenSSL::Cipher#final to your
     * encryption/decryption buffer or you will end up with decryption errors
     * or truncated data.
     *
     * Although this is not really necessary for streaming-mode ciphers, it is
     * still recommended to apply the same pattern of adding the output of
     * Cipher#final there as well - it also enables you to switch between
     * modes more easily in the future.
     *
     * === Encrypting and decrypting some data
     *
     *   data = "Very, very confidential data"
     *
     *   cipher = OpenSSL::Cipher::AES.new(128, :CBC)
     *   cipher.encrypt
     *   key = cipher.random_key
     *   iv = cipher.random_iv
     *
     *   encrypted = cipher.update(data) + cipher.final
     *   ...
     *   decipher = OpenSSL::Cipher::AES.new(128, :CBC)
     *   decipher.decrypt
     *   decipher.key = key
     *   decipher.iv = iv
     *
     *   plain = decipher.update(encrypted) + decipher.final
     *
     *   puts data == plain #=> true
     *
     * === Authenticated Encryption and Associated Data (AEAD)
     *
     * If the OpenSSL version used supports it, an Authenticated Encryption
     * mode (such as GCM or CCM) should always be preferred over any
     * unauthenticated mode. Currently, OpenSSL supports AE only in combination
     * with Associated Data (AEAD) where additional associated data is included
     * in the encryption process to compute a tag at the end of the encryption.
     * This tag will also be used in the decryption process and by verifying
     * its validity, the authenticity of a given ciphertext is established.
     *
     * This is superior to unauthenticated modes in that it allows to detect
     * if somebody effectively changed the ciphertext after it had been
     * encrypted. This prevents malicious modifications of the ciphertext that
     * could otherwise be exploited to modify ciphertexts in ways beneficial to
     * potential attackers.
     *
     * If no associated data is needed for encryption and later decryption,
     * the OpenSSL library still requires a value to be set - "" may be used in
     * case none is available. An example using the GCM (Galois Counter Mode):
     *
     *   cipher = OpenSSL::Cipher::AES.new(128, :GCM)
     *   cipher.encrypt
     *   key = cipher.random_key
     *   iv = cipher.random_iv
     *   cipher.auth_data = ""
     *
     *   encrypted = cipher.update(data) + cipher.final
     *   tag = cipher.auth_tag
     *
     *   decipher = OpenSSL::Cipher::AES.new(128, :GCM)
     *   decipher.decrypt
     *   decipher.key = key
     *   decipher.iv = iv
     *   decipher.auth_tag = tag
     *   decipher.auth_data = ""
     *
     *   plain = decipher.update(encrypted) + decipher.final
     *
     *   puts data == plain #=> true
     */
    cCipher = rb_define_class_under(mOSSL, "Cipher", rb_cObject);
    eCipherError = rb_define_class_under(cCipher, "CipherError", eOSSLError);

    rb_define_alloc_func(cCipher, ossl_cipher_alloc);
    rb_define_copy_func(cCipher, ossl_cipher_copy);
    rb_define_module_function(cCipher, "ciphers", ossl_s_ciphers, 0);
    rb_define_method(cCipher, "initialize", ossl_cipher_initialize, 1);
    rb_define_method(cCipher, "reset", ossl_cipher_reset, 0);
    rb_define_method(cCipher, "encrypt", ossl_cipher_encrypt, -1);
    rb_define_method(cCipher, "decrypt", ossl_cipher_decrypt, -1);
    rb_define_method(cCipher, "pkcs5_keyivgen", ossl_cipher_pkcs5_keyivgen, -1);
    rb_define_method(cCipher, "update", ossl_cipher_update, -1);
    rb_define_method(cCipher, "final", ossl_cipher_final, 0);
    rb_define_method(cCipher, "name", ossl_cipher_name, 0);
    rb_define_method(cCipher, "key=", ossl_cipher_set_key, 1);
    rb_define_method(cCipher, "auth_data=", ossl_cipher_set_auth_data, 1);
    rb_define_method(cCipher, "auth_tag=", ossl_cipher_set_auth_tag, 1);
    rb_define_method(cCipher, "auth_tag", ossl_cipher_get_auth_tag, -1);
    rb_define_method(cCipher, "authenticated?", ossl_cipher_is_authenticated, 0);
    rb_define_method(cCipher, "key_len=", ossl_cipher_set_key_length, 1);
    rb_define_method(cCipher, "key_len", ossl_cipher_key_length, 0);
    rb_define_method(cCipher, "iv=", ossl_cipher_set_iv, 1);
    rb_define_method(cCipher, "iv_len", ossl_cipher_iv_length, 0);
    rb_define_method(cCipher, "block_size", ossl_cipher_block_size, 0);
    rb_define_method(cCipher, "padding=", ossl_cipher_set_padding, 1);
}
Exemplo n.º 9
0
void Init_chaos_calendar() {
  mChaosCalendar = rb_define_module("ChaosCalendar");

  rb_define_module_function(mChaosCalendar, "occurrences", occurrences, 3);
  rb_define_module_function(mChaosCalendar, "duration_to_fixnum", duration_to_fixnum, 1);
}
Exemplo n.º 10
0
void Init_msp_curvy_slider(VALUE mNewton) {
	VALUE mCurvySlider = rb_define_module_under(mNewton, "CurvySlider");

	rb_define_module_function(mCurvySlider, "is_valid?", VALUEFUNC(MSNewton::CurvySlider::is_valid), 1);
	rb_define_module_function(mCurvySlider, "create", VALUEFUNC(MSNewton::CurvySlider::create), 1);
	rb_define_module_function(mCurvySlider, "add_point", VALUEFUNC(MSNewton::CurvySlider::add_point), 2);
	rb_define_module_function(mCurvySlider, "remove_point", VALUEFUNC(MSNewton::CurvySlider::remove_point), 2);
	rb_define_module_function(mCurvySlider, "get_points", VALUEFUNC(MSNewton::CurvySlider::get_points), 1);
	rb_define_module_function(mCurvySlider, "get_points_size", VALUEFUNC(MSNewton::CurvySlider::get_points), 1);
	rb_define_module_function(mCurvySlider, "clear_points", VALUEFUNC(MSNewton::CurvySlider::clear_points), 2);
	rb_define_module_function(mCurvySlider, "get_point_position", VALUEFUNC(MSNewton::CurvySlider::get_point_position), 2);
	rb_define_module_function(mCurvySlider, "set_point_position", VALUEFUNC(MSNewton::CurvySlider::set_point_position), 3);
	rb_define_module_function(mCurvySlider, "get_length", VALUEFUNC(MSNewton::CurvySlider::get_length), 1);
	rb_define_module_function(mCurvySlider, "get_cur_position", VALUEFUNC(MSNewton::CurvySlider::get_cur_position), 1);
	rb_define_module_function(mCurvySlider, "get_cur_velocity", VALUEFUNC(MSNewton::CurvySlider::get_cur_velocity), 1);
	rb_define_module_function(mCurvySlider, "get_cur_acceleration", VALUEFUNC(MSNewton::CurvySlider::get_cur_acceleration), 1);
	rb_define_module_function(mCurvySlider, "get_cur_point", VALUEFUNC(MSNewton::CurvySlider::get_cur_point), 1);
	rb_define_module_function(mCurvySlider, "get_cur_vector", VALUEFUNC(MSNewton::CurvySlider::get_cur_vector), 1);
	rb_define_module_function(mCurvySlider, "get_cur_tangent", VALUEFUNC(MSNewton::CurvySlider::get_cur_tangent), 1);
	rb_define_module_function(mCurvySlider, "get_linear_friction", VALUEFUNC(MSNewton::CurvySlider::get_linear_friction), 1);
	rb_define_module_function(mCurvySlider, "set_linear_friction", VALUEFUNC(MSNewton::CurvySlider::set_linear_friction), 2);
	rb_define_module_function(mCurvySlider, "get_angular_friction", VALUEFUNC(MSNewton::CurvySlider::get_angular_friction), 1);
	rb_define_module_function(mCurvySlider, "set_angular_friction", VALUEFUNC(MSNewton::CurvySlider::set_angular_friction), 2);
	rb_define_module_function(mCurvySlider, "get_controller", VALUEFUNC(MSNewton::CurvySlider::get_controller), 1);
	rb_define_module_function(mCurvySlider, "set_controller", VALUEFUNC(MSNewton::CurvySlider::set_controller), 2);
	rb_define_module_function(mCurvySlider, "loop_enabled?", VALUEFUNC(MSNewton::CurvySlider::loop_enabled), 1);
	rb_define_module_function(mCurvySlider, "enable_loop", VALUEFUNC(MSNewton::CurvySlider::enable_loop), 2);
	rb_define_module_function(mCurvySlider, "alignment_enabled?", VALUEFUNC(MSNewton::CurvySlider::alignment_enabled), 1);
	rb_define_module_function(mCurvySlider, "enable_alignment", VALUEFUNC(MSNewton::CurvySlider::enable_alignment), 2);
	rb_define_module_function(mCurvySlider, "rotation_enabled?", VALUEFUNC(MSNewton::CurvySlider::rotation_enabled), 1);
	rb_define_module_function(mCurvySlider, "enable_rotation", VALUEFUNC(MSNewton::CurvySlider::enable_rotation), 2);
	rb_define_module_function(mCurvySlider, "get_info_by_pos", VALUEFUNC(MSNewton::CurvySlider::get_info_by_pos), 2);
}
Exemplo n.º 11
0
void
InitVM_Math(void)
{
    rb_mMath = rb_define_module("Math");
    rb_eMathDomainError = rb_define_class_under(rb_mMath, "DomainError", rb_eStandardError);

#ifdef M_PI
    /*  Definition of the mathematical constant PI as a Float number. */
    rb_define_const(rb_mMath, "PI", DBL2NUM(M_PI));
#else
    rb_define_const(rb_mMath, "PI", DBL2NUM(atan(1.0)*4.0));
#endif

#ifdef M_E
    /*  Definition of the mathematical constant E (e) as a Float number. */
    rb_define_const(rb_mMath, "E", DBL2NUM(M_E));
#else
    rb_define_const(rb_mMath, "E", DBL2NUM(exp(1.0)));
#endif

    rb_define_module_function(rb_mMath, "atan2", math_atan2, 2);
    rb_define_module_function(rb_mMath, "cos", math_cos, 1);
    rb_define_module_function(rb_mMath, "sin", math_sin, 1);
    rb_define_module_function(rb_mMath, "tan", math_tan, 1);

    rb_define_module_function(rb_mMath, "acos", math_acos, 1);
    rb_define_module_function(rb_mMath, "asin", math_asin, 1);
    rb_define_module_function(rb_mMath, "atan", math_atan, 1);

    rb_define_module_function(rb_mMath, "cosh", math_cosh, 1);
    rb_define_module_function(rb_mMath, "sinh", math_sinh, 1);
    rb_define_module_function(rb_mMath, "tanh", math_tanh, 1);

    rb_define_module_function(rb_mMath, "acosh", math_acosh, 1);
    rb_define_module_function(rb_mMath, "asinh", math_asinh, 1);
    rb_define_module_function(rb_mMath, "atanh", math_atanh, 1);

    rb_define_module_function(rb_mMath, "exp", math_exp, 1);
    rb_define_module_function(rb_mMath, "log", math_log, -1);
    rb_define_module_function(rb_mMath, "log2", math_log2, 1);
    rb_define_module_function(rb_mMath, "log10", math_log10, 1);
    rb_define_module_function(rb_mMath, "sqrt", math_sqrt, 1);
    rb_define_module_function(rb_mMath, "cbrt", math_cbrt, 1);

    rb_define_module_function(rb_mMath, "frexp", math_frexp, 1);
    rb_define_module_function(rb_mMath, "ldexp", math_ldexp, 2);

    rb_define_module_function(rb_mMath, "hypot", math_hypot, 2);

    rb_define_module_function(rb_mMath, "erf",  math_erf,  1);
    rb_define_module_function(rb_mMath, "erfc", math_erfc, 1);

    rb_define_module_function(rb_mMath, "gamma", math_gamma, 1);
    rb_define_module_function(rb_mMath, "lgamma", math_lgamma, 1);
}
Exemplo n.º 12
0
/*
 * OpenSSL provides SSL, TLS and general purpose cryptography.  It wraps the
 * OpenSSL[http://www.openssl.org/] library.
 *
 * = Install
 *
 * OpenSSL comes bundled with the Standard Library of Ruby.
 *
 * This means the OpenSSL extension is compiled with Ruby and packaged on
 * build. During compile time, Ruby will need to link against the OpenSSL
 * library on your system. However, you cannot use openssl provided by Apple to
 * build standard library openssl.
 *
 * If you use OSX, you should install another openssl and run ```./configure
 * --with-openssl-dir=/path/to/another-openssl```. For Homebrew user, run `brew
 * install openssl` and then ```./configure --with-openssl-dir=`brew --prefix
 * openssl` ```.
 *
 * = Examples
 *
 * All examples assume you have loaded OpenSSL with:
 *
 *   require 'openssl'
 *
 * These examples build atop each other.  For example the key created in the
 * next is used in throughout these examples.
 *
 * == Keys
 *
 * === Creating a Key
 *
 * This example creates a 2048 bit RSA keypair and writes it to the current
 * directory.
 *
 *   key = OpenSSL::PKey::RSA.new 2048
 *
 *   open 'private_key.pem', 'w' do |io| io.write key.to_pem end
 *   open 'public_key.pem', 'w' do |io| io.write key.public_key.to_pem end
 *
 * === Exporting a Key
 *
 * Keys saved to disk without encryption are not secure as anyone who gets
 * ahold of the key may use it unless it is encrypted.  In order to securely
 * export a key you may export it with a pass phrase.
 *
 *   cipher = OpenSSL::Cipher.new 'AES-128-CBC'
 *   pass_phrase = 'my secure pass phrase goes here'
 *
 *   key_secure = key.export cipher, pass_phrase
 *
 *   open 'private.secure.pem', 'w' do |io|
 *     io.write key_secure
 *   end
 *
 * OpenSSL::Cipher.ciphers returns a list of available ciphers.
 *
 * === Loading a Key
 *
 * A key can also be loaded from a file.
 *
 *   key2 = OpenSSL::PKey::RSA.new File.read 'private_key.pem'
 *   key2.public? # => true
 *
 * or
 *
 *   key3 = OpenSSL::PKey::RSA.new File.read 'public_key.pem'
 *   key3.private? # => false
 *
 * === Loading an Encrypted Key
 *
 * OpenSSL will prompt you for your pass phrase when loading an encrypted key.
 * If you will not be able to type in the pass phrase you may provide it when
 * loading the key:
 *
 *   key4_pem = File.read 'private.secure.pem'
 *   key4 = OpenSSL::PKey::RSA.new key4_pem, pass_phrase
 *
 * == RSA Encryption
 *
 * RSA provides encryption and decryption using the public and private keys.
 * You can use a variety of padding methods depending upon the intended use of
 * encrypted data.
 *
 * === Encryption & Decryption
 *
 * Asymmetric public/private key encryption is slow and victim to attack in
 * cases where it is used without padding or directly to encrypt larger chunks
 * of data. Typical use cases for RSA encryption involve "wrapping" a symmetric
 * key with the public key of the recipient who would "unwrap" that symmetric
 * key again using their private key.
 * The following illustrates a simplified example of such a key transport
 * scheme. It shouldn't be used in practice, though, standardized protocols
 * should always be preferred.
 *
 *   wrapped_key = key.public_encrypt key
 *
 * A symmetric key encrypted with the public key can only be decrypted with
 * the corresponding private key of the recipient.
 *
 *   original_key = key.private_decrypt wrapped_key
 *
 * By default PKCS#1 padding will be used, but it is also possible to use
 * other forms of padding, see PKey::RSA for further details.
 *
 * === Signatures
 *
 * Using "private_encrypt" to encrypt some data with the private key is
 * equivalent to applying a digital signature to the data. A verifying
 * party may validate the signature by comparing the result of decrypting
 * the signature with "public_decrypt" to the original data. However,
 * OpenSSL::PKey already has methods "sign" and "verify" that handle
 * digital signatures in a standardized way - "private_encrypt" and
 * "public_decrypt" shouldn't be used in practice.
 *
 * To sign a document, a cryptographically secure hash of the document is
 * computed first, which is then signed using the private key.
 *
 *   digest = OpenSSL::Digest::SHA256.new
 *   signature = key.sign digest, document
 *
 * To validate the signature, again a hash of the document is computed and
 * the signature is decrypted using the public key. The result is then
 * compared to the hash just computed, if they are equal the signature was
 * valid.
 *
 *   digest = OpenSSL::Digest::SHA256.new
 *   if key.verify digest, signature, document
 *     puts 'Valid'
 *   else
 *     puts 'Invalid'
 *   end
 *
 * == PBKDF2 Password-based Encryption
 *
 * If supported by the underlying OpenSSL version used, Password-based
 * Encryption should use the features of PKCS5. If not supported or if
 * required by legacy applications, the older, less secure methods specified
 * in RFC 2898 are also supported (see below).
 *
 * PKCS5 supports PBKDF2 as it was specified in PKCS#5
 * v2.0[http://www.rsa.com/rsalabs/node.asp?id=2127]. It still uses a
 * password, a salt, and additionally a number of iterations that will
 * slow the key derivation process down. The slower this is, the more work
 * it requires being able to brute-force the resulting key.
 *
 * === Encryption
 *
 * The strategy is to first instantiate a Cipher for encryption, and
 * then to generate a random IV plus a key derived from the password
 * using PBKDF2. PKCS #5 v2.0 recommends at least 8 bytes for the salt,
 * the number of iterations largely depends on the hardware being used.
 *
 *   cipher = OpenSSL::Cipher.new 'AES-128-CBC'
 *   cipher.encrypt
 *   iv = cipher.random_iv
 *
 *   pwd = 'some hopefully not to easily guessable password'
 *   salt = OpenSSL::Random.random_bytes 16
 *   iter = 20000
 *   key_len = cipher.key_len
 *   digest = OpenSSL::Digest::SHA256.new
 *
 *   key = OpenSSL::PKCS5.pbkdf2_hmac(pwd, salt, iter, key_len, digest)
 *   cipher.key = key
 *
 *   Now encrypt the data:
 *
 *   encrypted = cipher.update document
 *   encrypted << cipher.final
 *
 * === Decryption
 *
 * Use the same steps as before to derive the symmetric AES key, this time
 * setting the Cipher up for decryption.
 *
 *   cipher = OpenSSL::Cipher.new 'AES-128-CBC'
 *   cipher.decrypt
 *   cipher.iv = iv # the one generated with #random_iv
 *
 *   pwd = 'some hopefully not to easily guessable password'
 *   salt = ... # the one generated above
 *   iter = 20000
 *   key_len = cipher.key_len
 *   digest = OpenSSL::Digest::SHA256.new
 *
 *   key = OpenSSL::PKCS5.pbkdf2_hmac(pwd, salt, iter, key_len, digest)
 *   cipher.key = key
 *
 *   Now decrypt the data:
 *
 *   decrypted = cipher.update encrypted
 *   decrypted << cipher.final
 *
 * == PKCS #5 Password-based Encryption
 *
 * PKCS #5 is a password-based encryption standard documented at
 * RFC2898[http://www.ietf.org/rfc/rfc2898.txt].  It allows a short password or
 * passphrase to be used to create a secure encryption key. If possible, PBKDF2
 * as described above should be used if the circumstances allow it.
 *
 * PKCS #5 uses a Cipher, a pass phrase and a salt to generate an encryption
 * key.
 *
 *   pass_phrase = 'my secure pass phrase goes here'
 *   salt = '8 octets'
 *
 * === Encryption
 *
 * First set up the cipher for encryption
 *
 *   encryptor = OpenSSL::Cipher.new 'AES-128-CBC'
 *   encryptor.encrypt
 *   encryptor.pkcs5_keyivgen pass_phrase, salt
 *
 * Then pass the data you want to encrypt through
 *
 *   encrypted = encryptor.update 'top secret document'
 *   encrypted << encryptor.final
 *
 * === Decryption
 *
 * Use a new Cipher instance set up for decryption
 *
 *   decryptor = OpenSSL::Cipher.new 'AES-128-CBC'
 *   decryptor.decrypt
 *   decryptor.pkcs5_keyivgen pass_phrase, salt
 *
 * Then pass the data you want to decrypt through
 *
 *   plain = decryptor.update encrypted
 *   plain << decryptor.final
 *
 * == X509 Certificates
 *
 * === Creating a Certificate
 *
 * This example creates a self-signed certificate using an RSA key and a SHA1
 * signature.
 *
 *   name = OpenSSL::X509::Name.parse 'CN=nobody/DC=example'
 *
 *   cert = OpenSSL::X509::Certificate.new
 *   cert.version = 2
 *   cert.serial = 0
 *   cert.not_before = Time.now
 *   cert.not_after = Time.now + 3600
 *
 *   cert.public_key = key.public_key
 *   cert.subject = name
 *
 * === Certificate Extensions
 *
 * You can add extensions to the certificate with
 * OpenSSL::SSL::ExtensionFactory to indicate the purpose of the certificate.
 *
 *   extension_factory = OpenSSL::X509::ExtensionFactory.new nil, cert
 *
 *   cert.add_extension \
 *     extension_factory.create_extension('basicConstraints', 'CA:FALSE', true)
 *
 *   cert.add_extension \
 *     extension_factory.create_extension(
 *       'keyUsage', 'keyEncipherment,dataEncipherment,digitalSignature')
 *
 *   cert.add_extension \
 *     extension_factory.create_extension('subjectKeyIdentifier', 'hash')
 *
 * The list of supported extensions (and in some cases their possible values)
 * can be derived from the "objects.h" file in the OpenSSL source code.
 *
 * === Signing a Certificate
 *
 * To sign a certificate set the issuer and use OpenSSL::X509::Certificate#sign
 * with a digest algorithm.  This creates a self-signed cert because we're using
 * the same name and key to sign the certificate as was used to create the
 * certificate.
 *
 *   cert.issuer = name
 *   cert.sign key, OpenSSL::Digest::SHA1.new
 *
 *   open 'certificate.pem', 'w' do |io| io.write cert.to_pem end
 *
 * === Loading a Certificate
 *
 * Like a key, a cert can also be loaded from a file.
 *
 *   cert2 = OpenSSL::X509::Certificate.new File.read 'certificate.pem'
 *
 * === Verifying a Certificate
 *
 * Certificate#verify will return true when a certificate was signed with the
 * given public key.
 *
 *   raise 'certificate can not be verified' unless cert2.verify key
 *
 * == Certificate Authority
 *
 * A certificate authority (CA) is a trusted third party that allows you to
 * verify the ownership of unknown certificates.  The CA issues key signatures
 * that indicate it trusts the user of that key.  A user encountering the key
 * can verify the signature by using the CA's public key.
 *
 * === CA Key
 *
 * CA keys are valuable, so we encrypt and save it to disk and make sure it is
 * not readable by other users.
 *
 *   ca_key = OpenSSL::PKey::RSA.new 2048
 *
 *   cipher = OpenSSL::Cipher::Cipher.new 'AES-128-CBC'
 *
 *   open 'ca_key.pem', 'w', 0400 do |io|
 *     io.write ca_key.export(cipher, pass_phrase)
 *   end
 *
 * === CA Certificate
 *
 * A CA certificate is created the same way we created a certificate above, but
 * with different extensions.
 *
 *   ca_name = OpenSSL::X509::Name.parse 'CN=ca/DC=example'
 *
 *   ca_cert = OpenSSL::X509::Certificate.new
 *   ca_cert.serial = 0
 *   ca_cert.version = 2
 *   ca_cert.not_before = Time.now
 *   ca_cert.not_after = Time.now + 86400
 *
 *   ca_cert.public_key = ca_key.public_key
 *   ca_cert.subject = ca_name
 *   ca_cert.issuer = ca_name
 *
 *   extension_factory = OpenSSL::X509::ExtensionFactory.new
 *   extension_factory.subject_certificate = ca_cert
 *   extension_factory.issuer_certificate = ca_cert
 *
 *   ca_cert.add_extension \
 *     extension_factory.create_extension('subjectKeyIdentifier', 'hash')
 *
 * This extension indicates the CA's key may be used as a CA.
 *
 *   ca_cert.add_extension \
 *     extension_factory.create_extension('basicConstraints', 'CA:TRUE', true)
 *
 * This extension indicates the CA's key may be used to verify signatures on
 * both certificates and certificate revocations.
 *
 *   ca_cert.add_extension \
 *     extension_factory.create_extension(
 *       'keyUsage', 'cRLSign,keyCertSign', true)
 *
 * Root CA certificates are self-signed.
 *
 *   ca_cert.sign ca_key, OpenSSL::Digest::SHA1.new
 *
 * The CA certificate is saved to disk so it may be distributed to all the
 * users of the keys this CA will sign.
 *
 *   open 'ca_cert.pem', 'w' do |io|
 *     io.write ca_cert.to_pem
 *   end
 *
 * === Certificate Signing Request
 *
 * The CA signs keys through a Certificate Signing Request (CSR).  The CSR
 * contains the information necessary to identify the key.
 *
 *   csr = OpenSSL::X509::Request.new
 *   csr.version = 0
 *   csr.subject = name
 *   csr.public_key = key.public_key
 *   csr.sign key, OpenSSL::Digest::SHA1.new
 *
 * A CSR is saved to disk and sent to the CA for signing.
 *
 *   open 'csr.pem', 'w' do |io|
 *     io.write csr.to_pem
 *   end
 *
 * === Creating a Certificate from a CSR
 *
 * Upon receiving a CSR the CA will verify it before signing it.  A minimal
 * verification would be to check the CSR's signature.
 *
 *   csr = OpenSSL::X509::Request.new File.read 'csr.pem'
 *
 *   raise 'CSR can not be verified' unless csr.verify csr.public_key
 *
 * After verification a certificate is created, marked for various usages,
 * signed with the CA key and returned to the requester.
 *
 *   csr_cert = OpenSSL::X509::Certificate.new
 *   csr_cert.serial = 0
 *   csr_cert.version = 2
 *   csr_cert.not_before = Time.now
 *   csr_cert.not_after = Time.now + 600
 *
 *   csr_cert.subject = csr.subject
 *   csr_cert.public_key = csr.public_key
 *   csr_cert.issuer = ca_cert.subject
 *
 *   extension_factory = OpenSSL::X509::ExtensionFactory.new
 *   extension_factory.subject_certificate = csr_cert
 *   extension_factory.issuer_certificate = ca_cert
 *
 *   csr_cert.add_extension \
 *     extension_factory.create_extension('basicConstraints', 'CA:FALSE')
 *
 *   csr_cert.add_extension \
 *     extension_factory.create_extension(
 *       'keyUsage', 'keyEncipherment,dataEncipherment,digitalSignature')
 *
 *   csr_cert.add_extension \
 *     extension_factory.create_extension('subjectKeyIdentifier', 'hash')
 *
 *   csr_cert.sign ca_key, OpenSSL::Digest::SHA1.new
 *
 *   open 'csr_cert.pem', 'w' do |io|
 *     io.write csr_cert.to_pem
 *   end
 *
 * == SSL and TLS Connections
 *
 * Using our created key and certificate we can create an SSL or TLS connection.
 * An SSLContext is used to set up an SSL session.
 *
 *   context = OpenSSL::SSL::SSLContext.new
 *
 * === SSL Server
 *
 * An SSL server requires the certificate and private key to communicate
 * securely with its clients:
 *
 *   context.cert = cert
 *   context.key = key
 *
 * Then create an SSLServer with a TCP server socket and the context.  Use the
 * SSLServer like an ordinary TCP server.
 *
 *   require 'socket'
 *
 *   tcp_server = TCPServer.new 5000
 *   ssl_server = OpenSSL::SSL::SSLServer.new tcp_server, context
 *
 *   loop do
 *     ssl_connection = ssl_server.accept
 *
 *     data = connection.gets
 *
 *     response = "I got #{data.dump}"
 *     puts response
 *
 *     connection.puts "I got #{data.dump}"
 *     connection.close
 *   end
 *
 * === SSL client
 *
 * An SSL client is created with a TCP socket and the context.
 * SSLSocket#connect must be called to initiate the SSL handshake and start
 * encryption.  A key and certificate are not required for the client socket.
 *
 *   require 'socket'
 *
 *   tcp_client = TCPSocket.new 'localhost', 5000
 *   ssl_client = OpenSSL::SSL::SSLSocket.new client_socket, context
 *   ssl_client.connect
 *
 *   ssl_client.puts "hello server!"
 *   puts ssl_client.gets
 *
 * === Peer Verification
 *
 * An unverified SSL connection does not provide much security.  For enhanced
 * security the client or server can verify the certificate of its peer.
 *
 * The client can be modified to verify the server's certificate against the
 * certificate authority's certificate:
 *
 *   context.ca_file = 'ca_cert.pem'
 *   context.verify_mode = OpenSSL::SSL::VERIFY_PEER
 *
 *   require 'socket'
 *
 *   tcp_client = TCPSocket.new 'localhost', 5000
 *   ssl_client = OpenSSL::SSL::SSLSocket.new client_socket, context
 *   ssl_client.connect
 *
 *   ssl_client.puts "hello server!"
 *   puts ssl_client.gets
 *
 * If the server certificate is invalid or <tt>context.ca_file</tt> is not set
 * when verifying peers an OpenSSL::SSL::SSLError will be raised.
 *
 */
void
Init_openssl(void)
{
    /*
     * Init timezone info
     */
#if 0
    tzset();
#endif

    /*
     * Init all digests, ciphers
     */
    /* CRYPTO_malloc_init(); */
    /* ENGINE_load_builtin_engines(); */
    OpenSSL_add_ssl_algorithms();
    OpenSSL_add_all_algorithms();
    ERR_load_crypto_strings();
    SSL_load_error_strings();

    /*
     * FIXME:
     * On unload do:
     */
#if 0
    CONF_modules_unload(1);
    destroy_ui_method();
    EVP_cleanup();
    ENGINE_cleanup();
    CRYPTO_cleanup_all_ex_data();
    ERR_remove_state(0);
    ERR_free_strings();
#endif

    /*
     * Init main module
     */
    mOSSL = rb_define_module("OpenSSL");
    rb_global_variable(&mOSSL);

    /*
     * OpenSSL ruby extension version
     */
    rb_define_const(mOSSL, "VERSION", rb_str_new2(OSSL_VERSION));

    /*
     * Version of OpenSSL the ruby OpenSSL extension was built with
     */
    rb_define_const(mOSSL, "OPENSSL_VERSION", rb_str_new2(OPENSSL_VERSION_TEXT));

    /*
     * Version of OpenSSL the ruby OpenSSL extension is running with
     */
    rb_define_const(mOSSL, "OPENSSL_LIBRARY_VERSION", rb_str_new2(SSLeay_version(SSLEAY_VERSION)));

    /*
     * Version number of OpenSSL the ruby OpenSSL extension was built with
     * (base 16)
     */
    rb_define_const(mOSSL, "OPENSSL_VERSION_NUMBER", INT2NUM(OPENSSL_VERSION_NUMBER));

    /*
     * Boolean indicating whether OpenSSL is FIPS-enabled or not
     */
#ifdef HAVE_OPENSSL_FIPS
    rb_define_const(mOSSL, "OPENSSL_FIPS", Qtrue);
#else
    rb_define_const(mOSSL, "OPENSSL_FIPS", Qfalse);
#endif
    rb_define_module_function(mOSSL, "fips_mode=", ossl_fips_mode_set, 1);

    /*
     * Generic error,
     * common for all classes under OpenSSL module
     */
    eOSSLError = rb_define_class_under(mOSSL,"OpenSSLError",rb_eStandardError);
    rb_global_variable(&eOSSLError);

    /*
     * Verify callback Proc index for ext-data
     */
    if ((ossl_verify_cb_idx = X509_STORE_CTX_get_ex_new_index(0, (void *)"ossl_verify_cb_idx", 0, 0, 0)) < 0)
        ossl_raise(eOSSLError, "X509_STORE_CTX_get_ex_new_index");

    /*
     * Init debug core
     */
    dOSSL = Qfalse;
    rb_global_variable(&dOSSL);

    rb_define_module_function(mOSSL, "debug", ossl_debug_get, 0);
    rb_define_module_function(mOSSL, "debug=", ossl_debug_set, 1);
    rb_define_module_function(mOSSL, "errors", ossl_get_errors, 0);

    /*
     * Get ID of to_der
     */
    ossl_s_to_der = rb_intern("to_der");

    Init_ossl_locks();

    /*
     * Init components
     */
    Init_ossl_bn();
    Init_ossl_cipher();
    Init_ossl_config();
    Init_ossl_digest();
    Init_ossl_hmac();
    Init_ossl_ns_spki();
    Init_ossl_pkcs12();
    Init_ossl_pkcs7();
    Init_ossl_pkcs5();
    Init_ossl_pkey();
    Init_ossl_rand();
    Init_ossl_ssl();
    Init_ossl_x509();
    Init_ossl_ocsp();
    Init_ossl_engine();
    Init_ossl_asn1();
}
Exemplo n.º 13
0
void
define_ruby_module()
{
  if (rb_module)
    return;
  rb_module = rb_define_module("OpenCV");

  /* OpenCV version */
  rb_define_const(rb_module, "CV_VERSION", rb_str_new2(CV_VERSION));
  rb_define_const(rb_module, "CV_MAJOR_VERSION", INT2FIX(CV_MAJOR_VERSION));
  rb_define_const(rb_module, "CV_MINOR_VERSION", INT2FIX(CV_MINOR_VERSION));
  rb_define_const(rb_module, "CV_SUBMINOR_VERSION", INT2FIX(CV_SUBMINOR_VERSION));

  rb_define_const(rb_module, "CV_VERSION_EPOCH", INT2FIX(CV_VERSION_EPOCH));
  rb_define_const(rb_module, "CV_VERSION_MAJOR", INT2FIX(CV_VERSION_MAJOR));
  rb_define_const(rb_module, "CV_VERSION_MINOR", INT2FIX(CV_VERSION_MINOR));
  rb_define_const(rb_module, "CV_VERSION_REVISION", INT2FIX(CV_VERSION_REVISION));

  /* 0: 8bit unsigned */
  rb_define_const(rb_module, "CV_8U", INT2FIX(CV_8U));
  /* 1: 8bit signed */
  rb_define_const(rb_module, "CV_8S", INT2FIX(CV_8S));
  /* 2: 16bit unsigned */
  rb_define_const(rb_module, "CV_16U", INT2FIX(CV_16U));
  /* 3: 16bit signed */
  rb_define_const(rb_module, "CV_16S", INT2FIX(CV_16S));
  /* 4: 32bit signed */
  rb_define_const(rb_module, "CV_32S", INT2FIX(CV_32S));
  /* 5: 32bit floating-point */
  rb_define_const(rb_module, "CV_32F", INT2FIX(CV_32F));
  /* 6: 64bit floating-point */
  rb_define_const(rb_module, "CV_64F", INT2FIX(CV_64F));
  
  /* Color types of loaded images */
  rb_define_const(rb_module, "CV_LOAD_IMAGE_UNCHANGED", INT2FIX(CV_LOAD_IMAGE_UNCHANGED));
  rb_define_const(rb_module, "CV_LOAD_IMAGE_GRAYSCALE", INT2FIX(CV_LOAD_IMAGE_GRAYSCALE));
  rb_define_const(rb_module, "CV_LOAD_IMAGE_COLOR", INT2FIX(CV_LOAD_IMAGE_COLOR));
  rb_define_const(rb_module, "CV_LOAD_IMAGE_ANYDEPTH", INT2FIX(CV_LOAD_IMAGE_ANYDEPTH));
  rb_define_const(rb_module, "CV_LOAD_IMAGE_ANYCOLOR", INT2FIX(CV_LOAD_IMAGE_ANYCOLOR));

  /* Format-specific save parameters */
  rb_define_const(rb_module, "CV_IMWRITE_JPEG_QUALITY", INT2FIX(CV_IMWRITE_JPEG_QUALITY));
  rb_define_const(rb_module, "CV_IMWRITE_PNG_COMPRESSION", INT2FIX(CV_IMWRITE_PNG_COMPRESSION));
  rb_define_const(rb_module, "CV_IMWRITE_PNG_STRATEGY", INT2FIX(CV_IMWRITE_PNG_STRATEGY));
  rb_define_const(rb_module, "CV_IMWRITE_PNG_STRATEGY_DEFAULT", INT2FIX(CV_IMWRITE_PNG_STRATEGY_DEFAULT));
  rb_define_const(rb_module, "CV_IMWRITE_PNG_STRATEGY_FILTERED", INT2FIX(CV_IMWRITE_PNG_STRATEGY_FILTERED));
  rb_define_const(rb_module, "CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY", INT2FIX(CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY));
  rb_define_const(rb_module, "CV_IMWRITE_PNG_STRATEGY_RLE", INT2FIX(CV_IMWRITE_PNG_STRATEGY_RLE));
  rb_define_const(rb_module, "CV_IMWRITE_PNG_STRATEGY_FIXED", INT2FIX(CV_IMWRITE_PNG_STRATEGY_FIXED));
  rb_define_const(rb_module, "CV_IMWRITE_PXM_BINARY", INT2FIX(CV_IMWRITE_PXM_BINARY));

  /* Types of morphological operations */
  rb_define_const(rb_module, "CV_MOP_OPEN", INT2FIX(CV_MOP_OPEN));
  rb_define_const(rb_module, "CV_MOP_CLOSE", INT2FIX(CV_MOP_CLOSE));
  rb_define_const(rb_module, "CV_MOP_GRADIENT", INT2FIX(CV_MOP_GRADIENT));
  rb_define_const(rb_module, "CV_MOP_TOPHAT", INT2FIX(CV_MOP_TOPHAT));
  rb_define_const(rb_module, "CV_MOP_BLACKHAT", INT2FIX(CV_MOP_BLACKHAT));

  /* Shape of the structuring elements */
  rb_define_const(rb_module, "CV_SHAPE_RECT", INT2FIX(CV_SHAPE_RECT));
  rb_define_const(rb_module, "CV_SHAPE_CROSS", INT2FIX(CV_SHAPE_CROSS));
  rb_define_const(rb_module, "CV_SHAPE_ELLIPSE", INT2FIX(CV_SHAPE_ELLIPSE));
  rb_define_const(rb_module, "CV_SHAPE_CUSTOM", INT2FIX(CV_SHAPE_CUSTOM));

  /* Types of the smoothing */
  rb_define_const(rb_module, "CV_BLUR_NO_SCALE", INT2FIX(CV_BLUR_NO_SCALE));
  rb_define_const(rb_module, "CV_BLUR", INT2FIX(CV_BLUR));
  rb_define_const(rb_module, "CV_GAUSSIAN", INT2FIX(CV_GAUSSIAN));
  rb_define_const(rb_module, "CV_MEDIAN", INT2FIX(CV_MEDIAN));
  rb_define_const(rb_module, "CV_BILATERAL", INT2FIX(CV_BILATERAL));

  /* Thresholding types */
  rb_define_const(rb_module, "CV_THRESH_BINARY", INT2FIX(CV_THRESH_BINARY));
  rb_define_const(rb_module, "CV_THRESH_BINARY_INV", INT2FIX(CV_THRESH_BINARY_INV));
  rb_define_const(rb_module, "CV_THRESH_TRUNC", INT2FIX(CV_THRESH_TRUNC));
  rb_define_const(rb_module, "CV_THRESH_TOZERO", INT2FIX(CV_THRESH_TOZERO));
  rb_define_const(rb_module, "CV_THRESH_TOZERO_INV", INT2FIX(CV_THRESH_TOZERO_INV));
  rb_define_const(rb_module, "CV_THRESH_OTSU", INT2FIX(CV_THRESH_OTSU));

  /* Adaptive methods */
  rb_define_const(rb_module, "CV_ADAPTIVE_THRESH_MEAN_C", INT2FIX(CV_ADAPTIVE_THRESH_MEAN_C));
  rb_define_const(rb_module, "CV_ADAPTIVE_THRESH_GAUSSIAN_C", INT2FIX(CV_ADAPTIVE_THRESH_GAUSSIAN_C));

  /* Border type */
  rb_define_const(rb_module, "IPL_BORDER_CONSTANT", INT2FIX(IPL_BORDER_CONSTANT));
  rb_define_const(rb_module, "IPL_BORDER_REPLICATE", INT2FIX(IPL_BORDER_REPLICATE));
  
  /* Retrieval mode */
  rb_define_const(rb_module, "CV_RETR_EXTERNAL", INT2FIX(CV_RETR_EXTERNAL));
  rb_define_const(rb_module, "CV_RETR_LIST", INT2FIX(CV_RETR_LIST));
  rb_define_const(rb_module, "CV_RETR_CCOMP", INT2FIX(CV_RETR_CCOMP));
  rb_define_const(rb_module, "CV_RETR_TREE", INT2FIX(CV_RETR_TREE));
  
  /* Approximation method */
  rb_define_const(rb_module, "CV_CHAIN_CODE", INT2FIX(CV_CHAIN_CODE));
  rb_define_const(rb_module, "CV_CHAIN_APPROX_NONE", INT2FIX(CV_CHAIN_APPROX_NONE));
  rb_define_const(rb_module, "CV_CHAIN_APPROX_SIMPLE", INT2FIX(CV_CHAIN_APPROX_SIMPLE));
  rb_define_const(rb_module, "CV_CHAIN_APPROX_TC89_L1", INT2FIX(CV_CHAIN_APPROX_TC89_L1));
  rb_define_const(rb_module, "CV_CHAIN_APPROX_TC89_KCOS", INT2FIX(CV_CHAIN_APPROX_TC89_KCOS));
  rb_define_const(rb_module, "CV_LINK_RUNS", INT2FIX(CV_LINK_RUNS));

  /* Termination criteria for iterative algorithms */
  rb_define_const(rb_module, "CV_TERMCRIT_ITER", INT2FIX(CV_TERMCRIT_ITER));
  rb_define_const(rb_module, "CV_TERMCRIT_NUMBER", INT2FIX(CV_TERMCRIT_NUMBER));
  rb_define_const(rb_module, "CV_TERMCRIT_EPS", INT2FIX(CV_TERMCRIT_EPS));

  /* Hough transform method */
  rb_define_const(rb_module, "CV_HOUGH_STANDARD", INT2FIX(CV_HOUGH_STANDARD));
  rb_define_const(rb_module, "CV_HOUGH_PROBABILISTIC", INT2FIX(CV_HOUGH_PROBABILISTIC));
  rb_define_const(rb_module, "CV_HOUGH_MULTI_SCALE", INT2FIX(CV_HOUGH_MULTI_SCALE));
  rb_define_const(rb_module, "CV_HOUGH_GRADIENT", INT2FIX(CV_HOUGH_GRADIENT));

  /* Inpaint method */
  rb_define_const(rb_module, "CV_INPAINT_NS", INT2FIX(CV_INPAINT_NS));
  rb_define_const(rb_module, "CV_INPAINT_TELEA", INT2FIX(CV_INPAINT_TELEA));

  /* Match template method */
  rb_define_const(rb_module, "CV_TM_SQDIFF", INT2FIX(CV_TM_SQDIFF));
  rb_define_const(rb_module, "CV_TM_SQDIFF_NORMED", INT2FIX(CV_TM_SQDIFF_NORMED));
  rb_define_const(rb_module, "CV_TM_CCORR", INT2FIX(CV_TM_CCORR));
  rb_define_const(rb_module, "CV_TM_CCORR_NORMED", INT2FIX(CV_TM_CCORR_NORMED));
  rb_define_const(rb_module, "CV_TM_CCOEFF", INT2FIX(CV_TM_CCOEFF));
  rb_define_const(rb_module, "CV_TM_CCOEFF_NORMED", INT2FIX(CV_TM_CCOEFF_NORMED));

  /* Comparison method */
  rb_define_const(rb_module, "CV_CONTOURS_MATCH_I1", INT2FIX(CV_CONTOURS_MATCH_I1));
  rb_define_const(rb_module, "CV_CONTOURS_MATCH_I2", INT2FIX(CV_CONTOURS_MATCH_I2));
  rb_define_const(rb_module, "CV_CONTOURS_MATCH_I3", INT2FIX(CV_CONTOURS_MATCH_I3));

  /* Fundamental matrix computing methods */
  rb_define_const(rb_module, "CV_FM_7POINT", INT2FIX(CV_FM_7POINT));
  rb_define_const(rb_module, "CV_FM_8POINT", INT2FIX(CV_FM_8POINT));
  rb_define_const(rb_module, "CV_FM_RANSAC", INT2FIX(CV_FM_RANSAC));
  rb_define_const(rb_module, "CV_FM_LMEDS", INT2FIX(CV_FM_LMEDS));

  /* Flags of window */
  rb_define_const(rb_module, "CV_WINDOW_AUTOSIZE", INT2FIX(CV_WINDOW_AUTOSIZE));

  /* Object detection mode */
  rb_define_const(rb_module, "CV_HAAR_DO_CANNY_PRUNING", INT2FIX(CV_HAAR_DO_CANNY_PRUNING));

  /* Interpolation methods */
  rb_define_const(rb_module, "CV_INTER_NN", INT2FIX(CV_INTER_NN));
  rb_define_const(rb_module, "CV_INTER_LINEAR", INT2FIX(CV_INTER_LINEAR));
  rb_define_const(rb_module, "CV_INTER_AREA", INT2FIX(CV_INTER_AREA));
  rb_define_const(rb_module, "CV_INTER_CUBIC", INT2FIX(CV_INTER_CUBIC));
  rb_define_const(rb_module, "CV_INTER_LANCZOS4", INT2FIX(CV_INTER_LANCZOS4));

  /* Warp affine optional flags */
  rb_define_const(rb_module, "CV_WARP_FILL_OUTLIERS", INT2FIX(CV_WARP_FILL_OUTLIERS));
  rb_define_const(rb_module, "CV_WARP_INVERSE_MAP", INT2FIX(CV_WARP_INVERSE_MAP));

  /* SVD optional flags */
  rb_define_const(rb_module, "CV_SVD_MODIFY_A", INT2FIX(CV_SVD_MODIFY_A));
  rb_define_const(rb_module, "CV_SVD_U_T", INT2FIX(CV_SVD_U_T));
  rb_define_const(rb_module, "CV_SVD_V_T", INT2FIX(CV_SVD_V_T));

  /* Norm types */
  rb_define_const(rb_module, "CV_NORM_INF", INT2FIX(cv::NORM_INF));
  rb_define_const(rb_module, "CV_NORM_L1", INT2FIX(cv::NORM_L1));
  rb_define_const(rb_module, "CV_NORM_L2", INT2FIX(cv::NORM_L2));
  rb_define_const(rb_module, "CV_NORM_MINMAX", INT2FIX(cv::NORM_MINMAX));

  /* Histogram representation format */
  rb_define_const(rb_module, "CV_HIST_ARRAY", INT2FIX(CV_HIST_ARRAY));
  rb_define_const(rb_module, "CV_HIST_SPARSE", INT2FIX(CV_HIST_SPARSE));
  rb_define_const(rb_module, "CV_HIST_TREE", INT2FIX(CV_HIST_TREE));
  rb_define_const(rb_module, "CV_HIST_UNIFORM", INT2FIX(CV_HIST_UNIFORM));

  /* Histogram comparison method */
  rb_define_const(rb_module, "CV_COMP_CORREL", INT2FIX(CV_COMP_CORREL));
  rb_define_const(rb_module, "CV_COMP_CHISQR", INT2FIX(CV_COMP_CHISQR));
  rb_define_const(rb_module, "CV_COMP_INTERSECT", INT2FIX(CV_COMP_INTERSECT));
  rb_define_const(rb_module, "CV_COMP_BHATTACHARYYA", INT2FIX(CV_COMP_BHATTACHARYYA));

  /* DFT and DCT flags */
  rb_define_const(rb_module, "CV_DXT_FORWARD", INT2FIX(CV_DXT_FORWARD));
  rb_define_const(rb_module, "CV_DXT_INVERSE", INT2FIX(CV_DXT_INVERSE));
  rb_define_const(rb_module, "CV_DXT_SCALE", INT2FIX(CV_DXT_SCALE));
  rb_define_const(rb_module, "CV_DXT_INV_SCALE", INT2FIX(CV_DXT_INV_SCALE));
  rb_define_const(rb_module, "CV_DXT_INVERSE_SCALE", INT2FIX(CV_DXT_INVERSE_SCALE));
  rb_define_const(rb_module, "CV_DXT_ROWS", INT2FIX(CV_DXT_ROWS));

  /* FindChessboardCorners flags */
  rb_define_const(rb_module, "CV_CALIB_CB_ADAPTIVE_THRESH", INT2FIX(CV_CALIB_CB_ADAPTIVE_THRESH));
  rb_define_const(rb_module, "CV_CALIB_CB_NORMALIZE_IMAGE", INT2FIX(CV_CALIB_CB_NORMALIZE_IMAGE));
  rb_define_const(rb_module, "CV_CALIB_CB_FILTER_QUADS", INT2FIX(CV_CALIB_CB_FILTER_QUADS));
  rb_define_const(rb_module, "CV_CALIB_CB_FAST_CHECK", INT2FIX(CV_CALIB_CB_FAST_CHECK));


  VALUE inversion_method = rb_hash_new();
  /* {:lu, :svd, :svd_sym(:svd_symmetric)}: Inversion method */
  rb_define_const(rb_module, "INVERSION_METHOD", inversion_method);
  REGISTER_HASH(inversion_method, "lu", CV_LU);
  REGISTER_HASH(inversion_method, "svd", CV_SVD);
  REGISTER_HASH(inversion_method, "svd_sym", CV_SVD_SYM);
  REGISTER_HASH(inversion_method, "svd_symmetric", CV_SVD_SYM);
    
  VALUE homography_calc_method = rb_hash_new();
  /* {:all, :ransac, :lmeds}: Methods used to computed homography matrix */
  rb_define_const(rb_module, "HOMOGRAPHY_CALC_METHOD", homography_calc_method);
  REGISTER_HASH(homography_calc_method, "all", 0);
  REGISTER_HASH(homography_calc_method, "ransac", CV_RANSAC);
  REGISTER_HASH(homography_calc_method, "lmeds", CV_LMEDS);

  VALUE depth = rb_hash_new();
  /* {:cv8u, :cv8s, :cv16u, :cv16s, :cv32s, :cv32f, :cv64f}: Depth of each pixel. */
  rb_define_const(rb_module, "DEPTH", depth);
  REGISTER_HASH(depth, "cv8u", CV_8U);
  REGISTER_HASH(depth, "cv8s", CV_8S);
  REGISTER_HASH(depth, "cv16u", CV_16U);
  REGISTER_HASH(depth, "cv16s", CV_16S);
  REGISTER_HASH(depth, "cv32s", CV_32S);
  REGISTER_HASH(depth, "cv32f", CV_32F);
  REGISTER_HASH(depth, "cv64f", CV_64F);
  
  VALUE connectivity = rb_hash_new();
  /* {:aa(:anti_alias)}: Determined by the closeness of pixel values */
  rb_define_const(rb_module, "CONNECTIVITY", connectivity);
  REGISTER_HASH(connectivity, "aa", CV_AA);
  REGISTER_HASH(connectivity, "anti_alias", CV_AA);

  VALUE structuring_element_shape = rb_hash_new();
  /* {:rect, :cross, :ellipse, :custom}: Shape of the structuring elements */
  rb_define_const(rb_module, "STRUCTURING_ELEMENT_SHAPE", structuring_element_shape);
  REGISTER_HASH(structuring_element_shape, "rect", CV_SHAPE_RECT);
  REGISTER_HASH(structuring_element_shape, "cross", CV_SHAPE_CROSS);
  REGISTER_HASH(structuring_element_shape, "ellipse", CV_SHAPE_ELLIPSE);
  REGISTER_HASH(structuring_element_shape, "custom", CV_SHAPE_CUSTOM);

  VALUE retrieval_mode = rb_hash_new();
  /* {:external, :list, :ccomp, :tree}: Retrieval mode */
  rb_define_const(rb_module, "RETRIEVAL_MODE", retrieval_mode);
  REGISTER_HASH(retrieval_mode, "external", CV_RETR_EXTERNAL);
  REGISTER_HASH(retrieval_mode, "list", CV_RETR_LIST);
  REGISTER_HASH(retrieval_mode, "ccomp", CV_RETR_CCOMP);
  REGISTER_HASH(retrieval_mode, "tree", CV_RETR_TREE);

  VALUE approx_chain_method = rb_hash_new();
  /* {:code, :approx_none, :approx_simple, :apporx_tc89_11, :approx_tc89_kcos}: Approximation method */
  rb_define_const(rb_module, "APPROX_CHAIN_METHOD", approx_chain_method);
  REGISTER_HASH(approx_chain_method, "code", CV_CHAIN_CODE);
  REGISTER_HASH(approx_chain_method, "approx_none", CV_CHAIN_APPROX_NONE);
  REGISTER_HASH(approx_chain_method, "approx_simple", CV_CHAIN_APPROX_SIMPLE);
  REGISTER_HASH(approx_chain_method, "approx_tc89_l1", CV_CHAIN_APPROX_TC89_L1);
  REGISTER_HASH(approx_chain_method, "approx_tc89_kcos", CV_CHAIN_APPROX_TC89_KCOS);
  
  VALUE approx_poly_method = rb_hash_new();
  /* {:dp}: Approximation method (polygon) */
  rb_define_const(rb_module, "APPROX_POLY_METHOD", approx_poly_method);
  REGISTER_HASH(approx_poly_method, "dp", CV_POLY_APPROX_DP);

  VALUE match_template_method = rb_hash_new();
  /* {:sqdiff, :sqdiff_normed, :ccorr, :ccorr_normed, :ccoeff, :ccoeff_normed}: Match template method */
  rb_define_const(rb_module, "MATCH_TEMPLATE_METHOD", match_template_method);
  REGISTER_HASH(match_template_method, "sqdiff", CV_TM_SQDIFF);
  REGISTER_HASH(match_template_method, "sqdiff_normed", CV_TM_SQDIFF_NORMED);
  REGISTER_HASH(match_template_method, "ccorr", CV_TM_CCORR);
  REGISTER_HASH(match_template_method, "ccorr_normed", CV_TM_CCORR_NORMED);
  REGISTER_HASH(match_template_method, "ccoeff", CV_TM_CCOEFF);
  REGISTER_HASH(match_template_method, "ccoeff_normed", CV_TM_CCOEFF_NORMED);

  VALUE morphological_operation = rb_hash_new();
  /* {:open, :close, :gradient, :tophat, :blackhat}: Types of morphological operations */
  rb_define_const(rb_module, "MORPHOLOGICAL_OPERATION", morphological_operation);
  REGISTER_HASH(morphological_operation, "open", CV_MOP_OPEN);
  REGISTER_HASH(morphological_operation, "close", CV_MOP_CLOSE);
  REGISTER_HASH(morphological_operation, "gradient", CV_MOP_GRADIENT);
  REGISTER_HASH(morphological_operation, "tophat", CV_MOP_TOPHAT);
  REGISTER_HASH(morphological_operation, "blackhat", CV_MOP_BLACKHAT);

  VALUE smoothing_type = rb_hash_new();
  /* {:blur_no_scale, :blur, :gaussian, :median, :bilateral}: Types of smoothing */
  rb_define_const(rb_module, "SMOOTHING_TYPE", smoothing_type);
  REGISTER_HASH(smoothing_type, "blur_no_scale", CV_BLUR_NO_SCALE);
  REGISTER_HASH(smoothing_type, "blur", CV_BLUR);
  REGISTER_HASH(smoothing_type, "gaussian", CV_GAUSSIAN);
  REGISTER_HASH(smoothing_type, "median", CV_MEDIAN);
  REGISTER_HASH(smoothing_type, "bilateral", CV_BILATERAL);

  VALUE adaptive_method = rb_hash_new();
  /* {:mean_c, :gaussian_c}: Adaptive thresholding algorithm */
  rb_define_const(rb_module, "ADAPTIVE_METHOD", adaptive_method);
  REGISTER_HASH(adaptive_method, "mean_c", CV_ADAPTIVE_THRESH_MEAN_C);
  REGISTER_HASH(adaptive_method, "gaussian_c", CV_ADAPTIVE_THRESH_GAUSSIAN_C);

  VALUE threshold_type = rb_hash_new();
  /* {:binary, :binary_inv, :trunc, :tozero, :tozero_inv, :otsu} : Thresholding types */
  rb_define_const(rb_module, "THRESHOLD_TYPE", threshold_type);
  REGISTER_HASH(threshold_type, "binary", CV_THRESH_BINARY);
  REGISTER_HASH(threshold_type, "binary_inv", CV_THRESH_BINARY_INV);
  REGISTER_HASH(threshold_type, "trunc", CV_THRESH_TRUNC);
  REGISTER_HASH(threshold_type, "tozero", CV_THRESH_TOZERO);
  REGISTER_HASH(threshold_type, "tozero_inv", CV_THRESH_TOZERO_INV);
  REGISTER_HASH(threshold_type, "otsu", CV_THRESH_OTSU);

  VALUE hough_transform_method = rb_hash_new();
  /* {:standard, :probabilistic, :multi_scale} : Hough transform method */
  rb_define_const(rb_module, "HOUGH_TRANSFORM_METHOD", hough_transform_method);
  REGISTER_HASH(hough_transform_method, "standard", CV_HOUGH_STANDARD);
  REGISTER_HASH(hough_transform_method, "probabilistic", CV_HOUGH_PROBABILISTIC);
  REGISTER_HASH(hough_transform_method, "multi_scale", CV_HOUGH_MULTI_SCALE);
  REGISTER_HASH(hough_transform_method, "gradient", CV_HOUGH_GRADIENT);

  VALUE inpaint_method = rb_hash_new();
  /* {:ns, :telea} : Inpaint method */
  rb_define_const(rb_module, "INPAINT_METHOD", inpaint_method);
  REGISTER_HASH(inpaint_method, "ns", CV_INPAINT_NS);
  REGISTER_HASH(inpaint_method, "telea", CV_INPAINT_TELEA);

  VALUE comparison_method = rb_hash_new();
  /* Comparison method */
  rb_define_const(rb_module, "COMPARISON_METHOD", comparison_method);
  REGISTER_HASH(comparison_method, "i1", CV_CONTOURS_MATCH_I1);
  REGISTER_HASH(comparison_method, "i2", CV_CONTOURS_MATCH_I2);
  REGISTER_HASH(comparison_method, "i3", CV_CONTOURS_MATCH_I3);

  /* color convert methods */
  rb_define_module_function(rb_module, "BGR2BGRA", RUBY_METHOD_FUNC(rb_BGR2BGRA), 1);
  rb_define_module_function(rb_module, "RGB2RGBA", RUBY_METHOD_FUNC(rb_RGB2RGBA), 1);
  rb_define_module_function(rb_module, "BGRA2BGR", RUBY_METHOD_FUNC(rb_BGRA2BGR), 1);
  rb_define_module_function(rb_module, "RGBA2RGB", RUBY_METHOD_FUNC(rb_RGBA2RGB), 1);
  rb_define_module_function(rb_module, "BGR2RGBA", RUBY_METHOD_FUNC(rb_BGR2RGBA), 1);
  rb_define_module_function(rb_module, "RGB2BGRA", RUBY_METHOD_FUNC(rb_RGB2BGRA), 1);
  rb_define_module_function(rb_module, "RGBA2BGR", RUBY_METHOD_FUNC(rb_RGBA2BGR), 1);
  rb_define_module_function(rb_module, "BGRA2RGB", RUBY_METHOD_FUNC(rb_BGRA2RGB), 1);
  rb_define_module_function(rb_module, "BGR2RGB", RUBY_METHOD_FUNC(rb_BGR2RGB), 1);
  rb_define_module_function(rb_module, "RGB2BGR", RUBY_METHOD_FUNC(rb_RGB2BGR), 1);
  rb_define_module_function(rb_module, "BGRA2RGBA", RUBY_METHOD_FUNC(rb_BGRA2RGBA), 1);
  rb_define_module_function(rb_module, "RGBA2BGRA", RUBY_METHOD_FUNC(rb_RGBA2BGRA), 1);
  rb_define_module_function(rb_module, "BGR2GRAY", RUBY_METHOD_FUNC(rb_BGR2GRAY), 1);
  rb_define_module_function(rb_module, "RGB2GRAY", RUBY_METHOD_FUNC(rb_RGB2GRAY), 1);
  rb_define_module_function(rb_module, "GRAY2BGR", RUBY_METHOD_FUNC(rb_GRAY2BGR), 1);
  rb_define_module_function(rb_module, "GRAY2RGB", RUBY_METHOD_FUNC(rb_GRAY2RGB), 1);
  rb_define_module_function(rb_module, "GRAY2BGRA", RUBY_METHOD_FUNC(rb_GRAY2BGRA), 1);
  rb_define_module_function(rb_module, "GRAY2RGBA", RUBY_METHOD_FUNC(rb_GRAY2RGBA), 1);
  rb_define_module_function(rb_module, "BGRA2GRAY", RUBY_METHOD_FUNC(rb_BGRA2GRAY), 1);
  rb_define_module_function(rb_module, "RGBA2GRAY", RUBY_METHOD_FUNC(rb_RGBA2GRAY), 1);
  rb_define_module_function(rb_module, "BGR2BGR565", RUBY_METHOD_FUNC(rb_BGR2BGR565), 1);
  rb_define_module_function(rb_module, "RGB2BGR565", RUBY_METHOD_FUNC(rb_RGB2BGR565), 1);
  rb_define_module_function(rb_module, "BGR5652BGR", RUBY_METHOD_FUNC(rb_BGR5652BGR), 1);
  rb_define_module_function(rb_module, "BGR5652RGB", RUBY_METHOD_FUNC(rb_BGR5652RGB), 1);
  rb_define_module_function(rb_module, "BGRA2BGR565", RUBY_METHOD_FUNC(rb_BGRA2BGR565), 1);
  rb_define_module_function(rb_module, "RGBA2BGR565", RUBY_METHOD_FUNC(rb_RGBA2BGR565), 1);
  rb_define_module_function(rb_module, "BGR5652BGRA", RUBY_METHOD_FUNC(rb_BGR5652BGRA), 1);
  rb_define_module_function(rb_module, "BGR5652RGBA", RUBY_METHOD_FUNC(rb_BGR5652RGBA), 1);
  rb_define_module_function(rb_module, "GRAY2BGR565", RUBY_METHOD_FUNC(rb_GRAY2BGR565), 1);
  rb_define_module_function(rb_module, "BGR5652GRAY", RUBY_METHOD_FUNC(rb_BGR5652GRAY), 1);
  rb_define_module_function(rb_module, "BGR2BGR555", RUBY_METHOD_FUNC(rb_BGR2BGR555), 1);
  rb_define_module_function(rb_module, "RGB2BGR555", RUBY_METHOD_FUNC(rb_RGB2BGR555), 1);
  rb_define_module_function(rb_module, "BGR5552BGR", RUBY_METHOD_FUNC(rb_BGR5552BGR), 1);
  rb_define_module_function(rb_module, "BGR5552RGB", RUBY_METHOD_FUNC(rb_BGR5552RGB), 1);
  rb_define_module_function(rb_module, "BGRA2BGR555", RUBY_METHOD_FUNC(rb_BGRA2BGR555), 1);
  rb_define_module_function(rb_module, "RGBA2BGR555", RUBY_METHOD_FUNC(rb_RGBA2BGR555), 1);
  rb_define_module_function(rb_module, "BGR5552BGRA", RUBY_METHOD_FUNC(rb_BGR5552BGRA), 1);
  rb_define_module_function(rb_module, "BGR5552RGBA", RUBY_METHOD_FUNC(rb_BGR5552RGBA), 1);
  rb_define_module_function(rb_module, "GRAY2BGR555", RUBY_METHOD_FUNC(rb_GRAY2BGR555), 1);
  rb_define_module_function(rb_module, "BGR5552GRAY", RUBY_METHOD_FUNC(rb_BGR5552GRAY), 1);
  rb_define_module_function(rb_module, "BGR2XYZ", RUBY_METHOD_FUNC(rb_BGR2XYZ), 1);
  rb_define_module_function(rb_module, "RGB2XYZ", RUBY_METHOD_FUNC(rb_RGB2XYZ), 1);
  rb_define_module_function(rb_module, "XYZ2BGR", RUBY_METHOD_FUNC(rb_XYZ2BGR), 1);
  rb_define_module_function(rb_module, "XYZ2RGB", RUBY_METHOD_FUNC(rb_XYZ2RGB), 1);
  rb_define_module_function(rb_module, "BGR2YCrCb", RUBY_METHOD_FUNC(rb_BGR2YCrCb), 1);
  rb_define_module_function(rb_module, "RGB2YCrCb", RUBY_METHOD_FUNC(rb_RGB2YCrCb), 1);
  rb_define_module_function(rb_module, "YCrCb2BGR", RUBY_METHOD_FUNC(rb_YCrCb2BGR), 1);
  rb_define_module_function(rb_module, "YCrCb2RGB", RUBY_METHOD_FUNC(rb_YCrCb2RGB), 1);
  rb_define_module_function(rb_module, "BGR2HSV", RUBY_METHOD_FUNC(rb_BGR2HSV), 1);
  rb_define_module_function(rb_module, "RGB2HSV", RUBY_METHOD_FUNC(rb_RGB2HSV), 1);
  rb_define_module_function(rb_module, "BGR2Lab", RUBY_METHOD_FUNC(rb_BGR2Lab), 1);
  rb_define_module_function(rb_module, "RGB2Lab", RUBY_METHOD_FUNC(rb_RGB2Lab), 1);
  rb_define_module_function(rb_module, "BayerBG2BGR", RUBY_METHOD_FUNC(rb_BayerBG2BGR), 1);
  rb_define_module_function(rb_module, "BayerGB2BGR", RUBY_METHOD_FUNC(rb_BayerGB2BGR), 1);
  rb_define_module_function(rb_module, "BayerRG2BGR", RUBY_METHOD_FUNC(rb_BayerRG2BGR), 1);
  rb_define_module_function(rb_module, "BayerGR2BGR", RUBY_METHOD_FUNC(rb_BayerGR2BGR), 1);
  rb_define_module_function(rb_module, "BayerBG2RGB", RUBY_METHOD_FUNC(rb_BayerBG2RGB), 1);
  rb_define_module_function(rb_module, "BayerGB2RGB", RUBY_METHOD_FUNC(rb_BayerGB2RGB), 1);
  rb_define_module_function(rb_module, "BayerRG2RGB", RUBY_METHOD_FUNC(rb_BayerRG2RGB), 1);
  rb_define_module_function(rb_module, "BayerGR2RGB", RUBY_METHOD_FUNC(rb_BayerGR2RGB), 1);
  rb_define_module_function(rb_module, "BGR2Luv", RUBY_METHOD_FUNC(rb_BGR2Luv), 1);
  rb_define_module_function(rb_module, "RGB2Luv", RUBY_METHOD_FUNC(rb_RGB2Luv), 1);
  rb_define_module_function(rb_module, "BGR2HLS", RUBY_METHOD_FUNC(rb_BGR2HLS), 1);
  rb_define_module_function(rb_module, "RGB2HLS", RUBY_METHOD_FUNC(rb_RGB2HLS), 1);
  rb_define_module_function(rb_module, "HSV2BGR", RUBY_METHOD_FUNC(rb_HSV2BGR), 1);
  rb_define_module_function(rb_module, "HSV2RGB", RUBY_METHOD_FUNC(rb_HSV2RGB), 1);
  rb_define_module_function(rb_module, "Lab2BGR", RUBY_METHOD_FUNC(rb_Lab2BGR), 1);
  rb_define_module_function(rb_module, "Lab2RGB", RUBY_METHOD_FUNC(rb_Lab2RGB), 1);
  rb_define_module_function(rb_module, "Luv2BGR", RUBY_METHOD_FUNC(rb_Luv2BGR), 1);
  rb_define_module_function(rb_module, "Luv2RGB", RUBY_METHOD_FUNC(rb_Luv2RGB), 1);
  rb_define_module_function(rb_module, "HLS2BGR", RUBY_METHOD_FUNC(rb_HLS2BGR), 1);
  rb_define_module_function(rb_module, "HLS2RGB", RUBY_METHOD_FUNC(rb_HLS2RGB), 1);

  rb_define_module_function(rb_module, "build_information", RUBY_METHOD_FUNC(rb_build_information), 0);
}
Exemplo n.º 14
0
void Init_llvmruby() {
  cLLVMRuby = rb_define_module("LLVM");

  cLLVMType = rb_define_class_under(cLLVMRuby, "Type", rb_cObject);
  cLLVMPointerType = rb_define_class_under(cLLVMRuby, "PointerType", cLLVMType);
  cLLVMStructType = rb_define_class_under(cLLVMRuby, "StructType", cLLVMType);
  cLLVMArrayType = rb_define_class_under(cLLVMRuby, "ArrayType", cLLVMType);
  cLLVMVectorType = rb_define_class_under(cLLVMRuby, "VectorType", cLLVMType);
  cLLVMFunctionType = rb_define_class_under(cLLVMRuby, "FunctionType", cLLVMType);

  cLLVMValue = rb_define_class_under(cLLVMRuby, "Value", rb_cObject);
  cLLVMUser = rb_define_class_under(cLLVMRuby, "User", cLLVMValue);
  cLLVMUse = rb_define_class_under(cLLVMRuby, "Use", rb_cObject);
  cLLVMModule = rb_define_class_under(cLLVMRuby, "Module", rb_cObject);
  cLLVMFunction = rb_define_class_under(cLLVMRuby, "Function", rb_cObject);
  cLLVMBasicBlock = rb_define_class_under(cLLVMRuby, "BasicBlock", cLLVMValue);   
  cLLVMBuilder = rb_define_class_under(cLLVMRuby, "Builder", rb_cObject);

  cLLVMInstruction = rb_define_class_under(cLLVMRuby, "Instruction", cLLVMUser);
  cLLVMUnaryInstruction = rb_define_class_under(cLLVMRuby, "UnaryInstruction", cLLVMInstruction);
  cLLVMBinaryOperator = rb_define_class_under(cLLVMRuby, "BinaryOperator", cLLVMInstruction);
  cLLVMTerminatorInst = rb_define_class_under(cLLVMRuby, "TerminatorInst", cLLVMInstruction);
  cLLVMAllocationInst = rb_define_class_under(cLLVMRuby, "AllocationInst", cLLVMInstruction);
  cLLVMBinaryOps = rb_define_class_under(cLLVMInstruction, "BinaryOps", rb_cObject);

  #define HANDLE_TERM_INST(Num, Opcode, Klass) cLLVM##Klass = rb_define_class_under(cLLVMRuby, #Klass, cLLVMTerminatorInst);
  #include "llvm/Instruction.def"

  cLLVMLoadInst = rb_define_class_under(cLLVMRuby, "LoadInst", cLLVMUnaryInstruction);
  cLLVMStoreInst = rb_define_class_under(cLLVMRuby, "StoreInst", cLLVMInstruction);
  cLLVMFreeInst = rb_define_class_under(cLLVMRuby, "FreeInst", cLLVMUnaryInstruction);
  cLLVMGetElementPtrInst = rb_define_class_under(cLLVMRuby, "GetElementPtrInst", cLLVMInstruction);
  cLLVMAllocaInst = rb_define_class_under(cLLVMRuby, "AllocaInst", cLLVMAllocationInst);
  cLLVMMallocInst = rb_define_class_under(cLLVMRuby, "MallocInst", cLLVMAllocationInst);

  cLLVMCmpInst = rb_define_class_under(cLLVMRuby, "CmpInst", cLLVMInstruction);
  cLLVMICmpInst = rb_define_class_under(cLLVMRuby, "ICmpInst", cLLVMCmpInst);
  cLLVMFCmpInst = rb_define_class_under(cLLVMRuby, "FCmpInst", cLLVMCmpInst);
  cLLVMPhi = rb_define_class_under(cLLVMRuby, "Phi", cLLVMValue);

  cLLVMPassManager = rb_define_class_under(cLLVMRuby, "PassManager", rb_cObject);
  cLLVMExecutionEngine = rb_define_class_under(cLLVMRuby, "ExecutionEngine", rb_cObject);

  init_types();
  rb_define_module_function(cLLVMType, "pointer", llvm_type_pointer, 1);
  rb_define_module_function(cLLVMType, "struct", llvm_type_struct, 1);
  rb_define_module_function(cLLVMType, "array", llvm_type_array, 2);
  rb_define_module_function(cLLVMType, "vector", llvm_type_vector, 2);
  rb_define_module_function(cLLVMType, "function", llvm_type_function, -1);
  rb_define_method(cLLVMType, "to_s", llvm_type_to_s, 0);
  rb_define_method(cLLVMType, "type_id", llvm_type_type_id, 0);

  rb_define_module_function(cLLVMValue, "get_constant", llvm_value_get_constant, 2);
  rb_define_module_function(cLLVMValue, "get_float_constant", llvm_value_get_float_constant, 1);
  rb_define_module_function(cLLVMValue, "get_double_constant", llvm_value_get_double_constant, 1);
  rb_define_module_function(cLLVMValue, "get_immediate_constant", llvm_value_get_immediate_constant, 1);
  rb_define_module_function(cLLVMValue, "get_struct_constant", llvm_value_get_struct_constant, -1);
  rb_define_method(cLLVMValue, "name", llvm_value_name, 0);
  rb_define_method(cLLVMValue, "name=", llvm_value_set_name, 1);
  rb_define_method(cLLVMValue, "type", llvm_value_type, 0);
  rb_define_method(cLLVMValue, "num_uses", llvm_value_num_uses, 0);
  rb_define_method(cLLVMValue, "used_in_basic_block?", llvm_value_used_in_basic_block, 1);
  rb_define_method(cLLVMValue, "replace_all_uses_with", llvm_value_replace_all_uses_with, 1);

  rb_define_method(cLLVMValue, "is_constant", llvm_value_is_constant, 0);
  rb_define_method(cLLVMValue, "is_int_constant", llvm_value_is_int_constant, 0);
  rb_define_method(cLLVMValue, "is_float_constant", llvm_value_is_float_constant, 0);
  rb_define_method(cLLVMValue, "get_int_constant_value", llvm_value_get_int_constant_value, 0);
  rb_define_method(cLLVMValue, "get_float_constant_value", llvm_value_get_float_constant_value, 0);
  rb_define_method(cLLVMValue, "is_null", llvm_value_is_null, 0);
  rb_define_method(cLLVMValue, "is_undef", llvm_value_is_undef, 0);

  rb_define_method(cLLVMUser, "get_operand_list", llvm_user_get_operand_list, 0);
  rb_define_method(cLLVMUser, "get_num_operands", llvm_user_get_num_operands, 0);
  rb_define_method(cLLVMUser, "get_operand", llvm_user_get_operand, 1);
  rb_define_method(cLLVMUser, "set_operand", llvm_user_set_operand, 2);
  rb_define_method(cLLVMUser, "drop_all_references", llvm_user_drop_all_references, 0);
  rb_define_method(cLLVMUser, "replace_uses_of_with", llvm_user_replace_uses_of_with, 2);


  init_instructions();

  rb_define_alloc_func(cLLVMModule, llvm_module_allocate);
  rb_define_module_function(cLLVMModule, "read_assembly", llvm_module_read_assembly, 1);
  rb_define_module_function(cLLVMModule, "read_bitcode", llvm_module_read_bitcode, 1);
  rb_define_method(cLLVMModule, "initialize", llvm_module_initialize, 1);
  rb_define_method(cLLVMModule, "get_or_insert_function", llvm_module_get_or_insert_function, 2);
  rb_define_method(cLLVMModule, "get_function", llvm_module_get_function, 1);
  rb_define_method(cLLVMModule, "global_constant", llvm_module_global_constant, 2);
  rb_define_method(cLLVMModule, "global_variable", llvm_module_global_variable, 2);
  rb_define_method(cLLVMModule, "external_function", llvm_module_external_function, 2);
  rb_define_method(cLLVMModule, "write_bitcode", llvm_module_write_bitcode, 1);
  rb_define_method(cLLVMModule, "inspect", llvm_module_inspect, 0);

  rb_define_method(cLLVMFunction, "create_block", llvm_function_create_block, 0);
  rb_define_method(cLLVMFunction, "arguments", llvm_function_arguments, 0);
  rb_define_method(cLLVMFunction, "inspect", llvm_function_inspect, 0);
  rb_define_method(cLLVMFunction, "get_basic_block_list", llvm_function_get_basic_block_list, 0);
  rb_define_method(cLLVMFunction, "set_gc", llvm_function_set_gc, 1);

  rb_define_method(cLLVMBasicBlock, "builder", llvm_basic_block_builder, 0);
  rb_define_method(cLLVMBasicBlock, "size", llvm_basic_block_size, 0);
  rb_define_method(cLLVMBasicBlock, "get_instruction_list", llvm_basic_block_get_instruction_list, 0);

  rb_define_method(cLLVMInstruction, "inspect", llvm_instruction_inspect, 0);
  rb_define_method(cLLVMInstruction, "get_opcode_name", llvm_instruction_get_opcode_name, 0);
  rb_define_method(cLLVMInstruction, "may_read_from_memory?", llvm_instruction_may_read_from_memory, 0);
  rb_define_method(cLLVMInstruction, "may_write_to_memory?", llvm_instruction_may_write_to_memory, 0);
  rb_define_method(cLLVMInstruction, "identical_to?", llvm_instruction_is_identical_to, 1);
  rb_define_method(cLLVMInstruction, "same_operation_as?", llvm_instruction_is_same_operation_as, 1);
  rb_define_method(cLLVMInstruction, "used_outside_of_block?", llvm_instruction_is_used_outside_of_block, 1);
  
  rb_define_method(cLLVMTerminatorInst, "num_successors", llvm_terminator_inst_num_successors, 0);
  rb_define_method(cLLVMTerminatorInst, "get_successor", llvm_terminator_inst_get_successor, 1);
  rb_define_method(cLLVMTerminatorInst, "set_successor", llvm_terminator_inst_set_successor, 2);

  rb_define_method(cLLVMBranchInst, "conditional?", llvm_branch_inst_is_conditional, 0);
  rb_define_method(cLLVMBranchInst, "unconditional?", llvm_branch_inst_is_unconditional, 0);
  rb_define_method(cLLVMBranchInst, "condition", llvm_branch_inst_get_condition, 0);
  rb_define_method(cLLVMBranchInst, "condition=", llvm_branch_inst_set_condition, 1);

  rb_define_method(cLLVMSwitchInst, "get_default_dest", llvm_switch_inst_get_default_dest, 0);
  rb_define_method(cLLVMSwitchInst, "get_num_cases", llvm_switch_inst_get_num_cases, 0);
  rb_define_method(cLLVMSwitchInst, "add_case", llvm_switch_inst_add_case, 2);

  rb_define_method(cLLVMAllocationInst, "array_allocation?", llvm_allocation_inst_is_array_allocation, 0);
  rb_define_method(cLLVMAllocationInst, "array_size", llvm_allocation_inst_array_size, 0);
  rb_define_method(cLLVMAllocationInst, "allocated_type", llvm_allocation_inst_allocated_type, 0);
  rb_define_method(cLLVMAllocationInst, "alignment", llvm_allocation_inst_alignment, 0);

  rb_define_method(cLLVMBuilder, "set_insert_point", llvm_builder_set_insert_point, 1);
  rb_define_method(cLLVMBuilder, "bin_op", llvm_builder_bin_op, 3);
  rb_define_method(cLLVMBuilder, "phi", llvm_builder_phi, 1);
  rb_define_method(cLLVMBuilder, "return", llvm_builder_return, 1);
  rb_define_method(cLLVMBuilder, "br", llvm_builder_br, 1);
  rb_define_method(cLLVMBuilder, "cond_br", llvm_builder_cond_br, 3);
  rb_define_method(cLLVMBuilder, "switch", llvm_builder_switch, 2);
  rb_define_method(cLLVMBuilder, "invoke", llvm_builder_invoke, -1);
  rb_define_method(cLLVMBuilder, "unwind", llvm_builder_unwind, 0);
  rb_define_method(cLLVMBuilder, "malloc", llvm_builder_malloc, 2);
  rb_define_method(cLLVMBuilder, "free", llvm_builder_free, 1);
  rb_define_method(cLLVMBuilder, "alloca", llvm_builder_alloca, 2);
  rb_define_method(cLLVMBuilder, "load", llvm_builder_load, -1);
  rb_define_method(cLLVMBuilder, "store", llvm_builder_store, -1);
  rb_define_method(cLLVMBuilder, "icmp", llvm_builder_icmp, 3);
  rb_define_method(cLLVMBuilder, "fcmp", llvm_builder_fcmp, 3);

  rb_define_method(cLLVMBuilder, "gep", llvm_builder_gep, 2);
  rb_define_method(cLLVMBuilder, "struct_gep", llvm_builder_struct_gep, 2);
  rb_define_method(cLLVMBuilder, "cast", llvm_builder_cast, 3);
  rb_define_method(cLLVMBuilder, "int_cast", llvm_builder_int_cast, 3);
  rb_define_method(cLLVMBuilder, "call", llvm_builder_call, -1);
  rb_define_method(cLLVMBuilder, "insert_element", llvm_builder_insert_element, 3);
  rb_define_method(cLLVMBuilder, "extract_element", llvm_builder_extract_element, 2);
  rb_define_method(cLLVMBuilder, "get_global", llvm_builder_get_global, 0);
  rb_define_method(cLLVMBuilder, "create_global_string_ptr", llvm_builder_create_global_string_ptr, 1);

  rb_define_method(cLLVMPhi, "add_incoming", llvm_phi_add_incoming, 2);

  rb_define_alloc_func(cLLVMModule, llvm_pass_manager_allocate);
  rb_define_method(cLLVMPassManager, "initialize", llvm_pass_manager_initialize, 0);
  rb_define_method(cLLVMPassManager, "run", llvm_pass_manager_run, 1);

  rb_define_module_function(cLLVMExecutionEngine, "get", llvm_execution_engine_get, 1);
  rb_define_module_function(cLLVMExecutionEngine, "run_function", llvm_execution_engine_run_function, -1);
  rb_define_module_function(cLLVMExecutionEngine, "run_autoconvert", llvm_execution_engine_run_autoconvert, 1);

  /*
  printf("sizeof long: %d\n", (int)sizeof(long));
  printf("sizeof ptr: %d\n", (int)sizeof(long*));
  printf("sizeof value: %d\n", (int)sizeof(VALUE));
  printf("sizeof array: %d\n", (int)sizeof(struct RArray));
  printf("sizeof int: %d\n", (int)sizeof(int));
  printf("sizeof char: %d\n", (int)sizeof(char));
  */
}
Exemplo n.º 15
0
static VALUE module_specs_rb_define_module_function(VALUE self, VALUE cls, VALUE str_name) {
  rb_define_module_function(cls, RSTRING_PTR(str_name), module_specs_test_method, 0);
  return Qnil;
}
Exemplo n.º 16
0
void Init_msp_servo(VALUE mNewton) {
	VALUE mServo = rb_define_module_under(mNewton, "Servo");

	rb_define_module_function(mServo, "is_valid?", VALUEFUNC(MSNewton::Servo::is_valid), 1);
	rb_define_module_function(mServo, "create", VALUEFUNC(MSNewton::Servo::create), 1);
	rb_define_module_function(mServo, "get_cur_angle", VALUEFUNC(MSNewton::Servo::get_cur_angle), 1);
	rb_define_module_function(mServo, "get_cur_omega", VALUEFUNC(MSNewton::Servo::get_cur_omega), 1);
	rb_define_module_function(mServo, "get_cur_acceleration", VALUEFUNC(MSNewton::Servo::get_cur_acceleration), 1);
	rb_define_module_function(mServo, "get_min", VALUEFUNC(MSNewton::Servo::get_min), 1);
	rb_define_module_function(mServo, "set_min", VALUEFUNC(MSNewton::Servo::set_min), 2);
	rb_define_module_function(mServo, "get_max", VALUEFUNC(MSNewton::Servo::get_max), 1);
	rb_define_module_function(mServo, "set_max", VALUEFUNC(MSNewton::Servo::set_max), 2);
	rb_define_module_function(mServo, "enable_limits", VALUEFUNC(MSNewton::Servo::enable_limits), 2);
	rb_define_module_function(mServo, "limits_enabled?", VALUEFUNC(MSNewton::Servo::limits_enabled), 1);
	rb_define_module_function(mServo, "get_rate", VALUEFUNC(MSNewton::Servo::get_rate), 1);
	rb_define_module_function(mServo, "set_rate", VALUEFUNC(MSNewton::Servo::set_rate), 2);
	rb_define_module_function(mServo, "get_power", VALUEFUNC(MSNewton::Servo::get_power), 1);
	rb_define_module_function(mServo, "set_power", VALUEFUNC(MSNewton::Servo::set_power), 2);
	rb_define_module_function(mServo, "get_reduction_ratio", VALUEFUNC(MSNewton::Servo::get_reduction_ratio), 1);
	rb_define_module_function(mServo, "set_reduction_ratio", VALUEFUNC(MSNewton::Servo::set_reduction_ratio), 2);
	rb_define_module_function(mServo, "get_controller", VALUEFUNC(MSNewton::Servo::get_controller), 1);
	rb_define_module_function(mServo, "set_controller", VALUEFUNC(MSNewton::Servo::set_controller), 2);
}
Exemplo n.º 17
0
void Init_gsl_sf_fermi_dirac(VALUE module)
{
  VALUE mgsl_sf_fermi;

  rb_define_module_function(module, "fermi_dirac_m1",  rb_gsl_sf_fermi_dirac_m1, 1);
  rb_define_module_function(module, "fermi_dirac_m1_e",  rb_gsl_sf_fermi_dirac_m1_e, 1);
  rb_define_module_function(module, "fermi_dirac_0",  rb_gsl_sf_fermi_dirac_0, 1);
  rb_define_module_function(module, "fermi_dirac_0_e",  rb_gsl_sf_fermi_dirac_0_e, 1);
  rb_define_module_function(module, "fermi_dirac_1",  rb_gsl_sf_fermi_dirac_1, 1);
  rb_define_module_function(module, "fermi_dirac_1_e",  rb_gsl_sf_fermi_dirac_1_e, 1);
  rb_define_module_function(module, "fermi_dirac_2",  rb_gsl_sf_fermi_dirac_2, 1);
  rb_define_module_function(module, "fermi_dirac_2_e",  rb_gsl_sf_fermi_dirac_2_e, 1);
  rb_define_module_function(module, "fermi_dirac_int",  rb_gsl_sf_fermi_dirac_int, 2);
  rb_define_module_function(module, "fermi_dirac_int_e",  rb_gsl_sf_fermi_dirac_int_e, 2);
  rb_define_module_function(module, "fermi_dirac_mhalf",  rb_gsl_sf_fermi_dirac_mhalf, 1);
  rb_define_module_function(module, "fermi_dirac_mhalf_e",  rb_gsl_sf_fermi_dirac_mhalf_e, 1);
  rb_define_module_function(module, "fermi_dirac_half",  rb_gsl_sf_fermi_dirac_half, 1);
  rb_define_module_function(module, "fermi_dirac_half_e",  rb_gsl_sf_fermi_dirac_half_e, 1);
  rb_define_module_function(module, "fermi_dirac_3half",  rb_gsl_sf_fermi_dirac_3half, 1);
  rb_define_module_function(module, "fermi_dirac_3half_e",  rb_gsl_sf_fermi_dirac_3half_e, 1);
  rb_define_module_function(module, "fermi_dirac_inc_0",  rb_gsl_sf_fermi_dirac_inc_0, 2);
  rb_define_module_function(module, "fermi_dirac_inc_0_e",  rb_gsl_sf_fermi_dirac_inc_0_e, 2);

  mgsl_sf_fermi = rb_define_module_under(module, "Fermi_Dirac");
  rb_define_module_function(mgsl_sf_fermi, "m1",  rb_gsl_sf_fermi_dirac_m1, 1);
  rb_define_module_function(mgsl_sf_fermi, "m1_e",  rb_gsl_sf_fermi_dirac_m1_e, 1);
  rb_define_module_function(mgsl_sf_fermi, "zero",  rb_gsl_sf_fermi_dirac_0, 1);
  rb_define_module_function(mgsl_sf_fermi, "zero_e",  rb_gsl_sf_fermi_dirac_0_e, 1);
  rb_define_module_function(mgsl_sf_fermi, "one",  rb_gsl_sf_fermi_dirac_1, 1);
  rb_define_module_function(mgsl_sf_fermi, "one_e",  rb_gsl_sf_fermi_dirac_1_e, 1);
  rb_define_module_function(mgsl_sf_fermi, "two",  rb_gsl_sf_fermi_dirac_2, 1);
  rb_define_module_function(mgsl_sf_fermi, "two_e",  rb_gsl_sf_fermi_dirac_2_e, 1);
  rb_define_module_function(mgsl_sf_fermi, "int",  rb_gsl_sf_fermi_dirac_int, 2);
  rb_define_module_function(mgsl_sf_fermi, "int_e",  rb_gsl_sf_fermi_dirac_int_e, 2);
  rb_define_module_function(mgsl_sf_fermi, "mhalf",  rb_gsl_sf_fermi_dirac_mhalf, 1);
  rb_define_module_function(mgsl_sf_fermi, "mhalf_e",  rb_gsl_sf_fermi_dirac_mhalf_e, 1);
  rb_define_module_function(mgsl_sf_fermi, "half",  rb_gsl_sf_fermi_dirac_half, 1);
  rb_define_module_function(mgsl_sf_fermi, "half_e",  rb_gsl_sf_fermi_dirac_half_e, 1);
  rb_define_module_function(mgsl_sf_fermi, "threehalf",  rb_gsl_sf_fermi_dirac_3half, 1);
  rb_define_module_function(mgsl_sf_fermi, "threehalf_e",  rb_gsl_sf_fermi_dirac_3half_e, 1);
  rb_define_module_function(mgsl_sf_fermi, "inc_0",  rb_gsl_sf_fermi_dirac_inc_0, 2);
  rb_define_module_function(mgsl_sf_fermi, "inc_0_e",  rb_gsl_sf_fermi_dirac_inc_0_e, 2);

}
Exemplo n.º 18
0
void
Init_Math(void)
{
    rb_mMath = rb_define_module("Math");

#ifdef M_PI
    rb_define_const(rb_mMath, "PI", DBL2NUM(M_PI));
#else
    rb_define_const(rb_mMath, "PI", DBL2NUM(atan(1.0)*4.0));
#endif

#ifdef M_E
    rb_define_const(rb_mMath, "E", DBL2NUM(M_E));
#else
    rb_define_const(rb_mMath, "E", DBL2NUM(exp(1.0)));
#endif

    rb_define_module_function(rb_mMath, "atan2", math_atan2, 2);
    rb_define_module_function(rb_mMath, "cos", math_cos, 1);
    rb_define_module_function(rb_mMath, "sin", math_sin, 1);
    rb_define_module_function(rb_mMath, "tan", math_tan, 1);

    rb_define_module_function(rb_mMath, "acos", math_acos, 1);
    rb_define_module_function(rb_mMath, "asin", math_asin, 1);
    rb_define_module_function(rb_mMath, "atan", math_atan, 1);

    rb_define_module_function(rb_mMath, "cosh", math_cosh, 1);
    rb_define_module_function(rb_mMath, "sinh", math_sinh, 1);
    rb_define_module_function(rb_mMath, "tanh", math_tanh, 1);

    rb_define_module_function(rb_mMath, "acosh", math_acosh, 1);
    rb_define_module_function(rb_mMath, "asinh", math_asinh, 1);
    rb_define_module_function(rb_mMath, "atanh", math_atanh, 1);

    rb_define_module_function(rb_mMath, "exp", math_exp, 1);
    rb_define_module_function(rb_mMath, "log", math_log, -1);
    rb_define_module_function(rb_mMath, "log2", math_log2, 1);
    rb_define_module_function(rb_mMath, "log10", math_log10, 1);
    rb_define_module_function(rb_mMath, "sqrt", math_sqrt, 1);
    rb_define_module_function(rb_mMath, "cbrt", math_cbrt, 1);

    rb_define_module_function(rb_mMath, "frexp", math_frexp, 1);
    rb_define_module_function(rb_mMath, "ldexp", math_ldexp, 2);

    rb_define_module_function(rb_mMath, "hypot", math_hypot, 2);

    rb_define_module_function(rb_mMath, "erf",  math_erf,  1);
    rb_define_module_function(rb_mMath, "erfc", math_erfc, 1);

    rb_define_module_function(rb_mMath, "gamma", math_gamma, 1);
    rb_define_module_function(rb_mMath, "lgamma", math_lgamma, 1);
}
Exemplo n.º 19
0
/*
 * Many operating systems allow signals to be sent to running
 * processes. Some signals have a defined effect on the process, while
 * others may be trapped at the code level and acted upon. For
 * example, your process may trap the USR1 signal and use it to toggle
 * debugging, and may use TERM to initiate a controlled shutdown.
 *
 *     pid = fork do
 *       Signal.trap("USR1") do
 *         $debug = !$debug
 *         puts "Debug now: #$debug"
 *       end
 *       Signal.trap("TERM") do
 *         puts "Terminating..."
 *         shutdown()
 *       end
 *       # . . . do some work . . .
 *     end
 *
 *     Process.detach(pid)
 *
 *     # Controlling program:
 *     Process.kill("USR1", pid)
 *     # ...
 *     Process.kill("USR1", pid)
 *     # ...
 *     Process.kill("TERM", pid)
 *
 * produces:
 *     Debug now: true
 *     Debug now: false
 *    Terminating...
 *
 * The list of available signal names and their interpretation is
 * system dependent. Signal delivery semantics may also vary between
 * systems; in particular signal delivery may not always be reliable.
 */
void
Init_signal(void)
{
    VALUE mSignal = rb_define_module("Signal");

    rb_define_global_function("trap", sig_trap, -1);
    rb_define_module_function(mSignal, "trap", sig_trap, -1);
    rb_define_module_function(mSignal, "list", sig_list, 0);
    rb_define_module_function(mSignal, "signame", sig_signame, 1);

    rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
    rb_define_method(rb_eSignal, "signo", esignal_signo, 0);
    rb_alias(rb_eSignal, rb_intern_const("signm"), rb_intern_const("message"));
    rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1);

    /* At this time, there is no subthread. Then sigmask guarantee atomics. */
    rb_disable_interrupt();

    install_sighandler(SIGINT, sighandler);
#ifdef SIGHUP
    install_sighandler(SIGHUP, sighandler);
#endif
#ifdef SIGQUIT
    install_sighandler(SIGQUIT, sighandler);
#endif
#ifdef SIGTERM
    install_sighandler(SIGTERM, sighandler);
#endif
#ifdef SIGALRM
    install_sighandler(SIGALRM, sighandler);
#endif
#ifdef SIGUSR1
    install_sighandler(SIGUSR1, sighandler);
#endif
#ifdef SIGUSR2
    install_sighandler(SIGUSR2, sighandler);
#endif

    if (!ruby_enable_coredump) {
#ifdef SIGBUS
	install_sighandler(SIGBUS, (sighandler_t)sigbus);
#endif
#ifdef SIGILL
	install_sighandler(SIGILL, (sighandler_t)sigill);
#endif
#ifdef SIGSEGV
# ifdef USE_SIGALTSTACK
	rb_register_sigaltstack(GET_THREAD());
# endif
	install_sighandler(SIGSEGV, (sighandler_t)sigsegv);
#endif
    }
#ifdef SIGPIPE
    install_sighandler(SIGPIPE, SIG_IGN);
#endif

#if defined(SIGCLD)
    init_sigchld(SIGCLD);
#elif defined(SIGCHLD)
    init_sigchld(SIGCHLD);
#endif

    rb_enable_interrupt();
}
Exemplo n.º 20
0
void Init_svd()
{
	VALUE module = rb_define_module("SVD\n");
	rb_define_module_function(module, "decompose", decompose, 3);
}		
Exemplo n.º 21
0
void
Init_dl(void)
{
    void Init_dlhandle(void);
    void Init_dlcfunc(void);
    void Init_dlptr(void);

    rbdl_id_cdecl = rb_intern_const("cdecl");
    rbdl_id_stdcall = rb_intern_const("stdcall");

    /* Document-module: DL
     *
     * A bridge to the dlopen() or dynamic library linker function.
     *
     * == Example
     *
     *   bash $> cat > sum.c <<EOF
     *   double sum(double *arry, int len)
     *   {
     *           double ret = 0;
     *           int i;
     *           for(i = 0; i < len; i++){
     *                   ret = ret + arry[i];
     *           }
     *           return ret;
     *   }
     *
     *   double split(double num)
     *   {
     *           double ret = 0;
     *           ret = num / 2;
     *           return ret;
     *   }
     *   EOF
     *   bash $> gcc -o libsum.so -shared sum.c
     *   bash $> cat > sum.rb <<EOF
     *   require 'dl'
     *   require 'dl/import'
     *
     *   module LibSum
     *           extend DL::Importer
     *           dlload './libsum.so'
     *           extern 'double sum(double*, int)'
     *           extern 'double split(double)'
     *   end
     *
     *   a = [2.0, 3.0, 4.0]
     *
     *   sum = LibSum.sum(a.pack("d*"), a.count)
     *   p LibSum.split(sum)
     *   EOF
     *   bash $> ruby sum.rb
     *   4.5
     *
     * WIN! :-)
     */
    rb_mDL = rb_define_module("DL");

    /*
     * Document-class: DL::DLError
     *
     * standard dynamic load exception
     */
    rb_eDLError = rb_define_class_under(rb_mDL, "DLError", rb_eStandardError);

    /*
     * Document-class: DL::DLTypeError
     *
     * dynamic load incorrect type exception
     */
    rb_eDLTypeError = rb_define_class_under(rb_mDL, "DLTypeError", rb_eDLError);

    /* Document-const: MAX_CALLBACK
     *
     * Maximum number of callbacks
     */
    rb_define_const(rb_mDL, "MAX_CALLBACK", INT2NUM(MAX_CALLBACK));

    /* Document-const: DLSTACK_SIZE
     *
     * Dynamic linker stack size
     */
    rb_define_const(rb_mDL, "DLSTACK_SIZE", INT2NUM(DLSTACK_SIZE));

    rb_dl_init_callbacks(rb_mDL);

    /* Document-const: RTLD_GLOBAL
     *
     * rtld DL::Handle flag.
     *
     * The symbols defined by this library will be made available for symbol
     * resolution of subsequently loaded libraries.
     */
    rb_define_const(rb_mDL, "RTLD_GLOBAL", INT2NUM(RTLD_GLOBAL));

    /* Document-const: RTLD_LAZY
     *
     * rtld DL::Handle flag.
     *
     * Perform lazy binding.  Only resolve symbols as the code that references
     * them is executed.  If the  symbol is never referenced, then it is never
     * resolved.  (Lazy binding is only performed for function references;
     * references to variables are always immediately bound when the library
     * is loaded.)
     */
    rb_define_const(rb_mDL, "RTLD_LAZY",   INT2NUM(RTLD_LAZY));

    /* Document-const: RTLD_NOW
     *
     * rtld DL::Handle flag.
     *
     * If this value is specified or the environment variable LD_BIND_NOW is
     * set to a nonempty string, all undefined symbols in the library are
     * resolved before dlopen() returns.  If this cannot be done an error is
     * returned.
     */
    rb_define_const(rb_mDL, "RTLD_NOW",    INT2NUM(RTLD_NOW));

    /* Document-const: TYPE_VOID
     *
     * DL::CFunc type - void
     */
    rb_define_const(rb_mDL, "TYPE_VOID",  INT2NUM(DLTYPE_VOID));

    /* Document-const: TYPE_VOIDP
     *
     * DL::CFunc type - void*
     */
    rb_define_const(rb_mDL, "TYPE_VOIDP",  INT2NUM(DLTYPE_VOIDP));

    /* Document-const: TYPE_CHAR
     *
     * DL::CFunc type - char
     */
    rb_define_const(rb_mDL, "TYPE_CHAR",  INT2NUM(DLTYPE_CHAR));

    /* Document-const: TYPE_SHORT
     *
     * DL::CFunc type - short
     */
    rb_define_const(rb_mDL, "TYPE_SHORT",  INT2NUM(DLTYPE_SHORT));

    /* Document-const: TYPE_INT
     *
     * DL::CFunc type - int
     */
    rb_define_const(rb_mDL, "TYPE_INT",  INT2NUM(DLTYPE_INT));

    /* Document-const: TYPE_LONG
     *
     * DL::CFunc type - long
     */
    rb_define_const(rb_mDL, "TYPE_LONG",  INT2NUM(DLTYPE_LONG));

#if HAVE_LONG_LONG
    /* Document-const: TYPE_LONG_LONG
     *
     * DL::CFunc type - long long
     */
    rb_define_const(rb_mDL, "TYPE_LONG_LONG",  INT2NUM(DLTYPE_LONG_LONG));
#endif

    /* Document-const: TYPE_FLOAT
     *
     * DL::CFunc type - float
     */
    rb_define_const(rb_mDL, "TYPE_FLOAT",  INT2NUM(DLTYPE_FLOAT));

    /* Document-const: TYPE_DOUBLE
     *
     * DL::CFunc type - double
     */
    rb_define_const(rb_mDL, "TYPE_DOUBLE",  INT2NUM(DLTYPE_DOUBLE));

    /* Document-const: TYPE_SIZE_T
     *
     * DL::CFunc type - size_t
     */
    rb_define_const(rb_mDL, "TYPE_SIZE_T",  INT2NUM(DLTYPE_SIZE_T));

    /* Document-const: TYPE_SSIZE_T
     *
     * DL::CFunc type - ssize_t
     */
    rb_define_const(rb_mDL, "TYPE_SSIZE_T", INT2NUM(DLTYPE_SSIZE_T));

    /* Document-const: TYPE_PTRDIFF_T
     *
     * DL::CFunc type - ptrdiff_t
     */
    rb_define_const(rb_mDL, "TYPE_PTRDIFF_T", INT2NUM(DLTYPE_PTRDIFF_T));

    /* Document-const: TYPE_INTPTR_T
     *
     * DL::CFunc type - intptr_t
     */
    rb_define_const(rb_mDL, "TYPE_INTPTR_T", INT2NUM(DLTYPE_INTPTR_T));

    /* Document-const: TYPE_UINTPTR_T
     *
     * DL::CFunc type - uintptr_t
     */
    rb_define_const(rb_mDL, "TYPE_UINTPTR_T", INT2NUM(DLTYPE_UINTPTR_T));

    /* Document-const: ALIGN_VOIDP
     *
     * The alignment size of a void*
     */
    rb_define_const(rb_mDL, "ALIGN_VOIDP", INT2NUM(ALIGN_VOIDP));

    /* Document-const: ALIGN_CHAR
     *
     * The alignment size of a char
     */
    rb_define_const(rb_mDL, "ALIGN_CHAR",  INT2NUM(ALIGN_CHAR));

    /* Document-const: ALIGN_SHORT
     *
     * The alignment size of a short
     */
    rb_define_const(rb_mDL, "ALIGN_SHORT", INT2NUM(ALIGN_SHORT));

    /* Document-const: ALIGN_INT
     *
     * The alignment size of an int
     */
    rb_define_const(rb_mDL, "ALIGN_INT",   INT2NUM(ALIGN_INT));

    /* Document-const: ALIGN_LONG
     *
     * The alignment size of a long
     */
    rb_define_const(rb_mDL, "ALIGN_LONG",  INT2NUM(ALIGN_LONG));

#if HAVE_LONG_LONG
    /* Document-const: ALIGN_LONG_LONG
     *
     * The alignment size of a long long
     */
    rb_define_const(rb_mDL, "ALIGN_LONG_LONG",  INT2NUM(ALIGN_LONG_LONG));
#endif

    /* Document-const: ALIGN_FLOAT
     *
     * The alignment size of a float
     */
    rb_define_const(rb_mDL, "ALIGN_FLOAT", INT2NUM(ALIGN_FLOAT));

    /* Document-const: ALIGN_DOUBLE
     *
     * The alignment size of a double
     */
    rb_define_const(rb_mDL, "ALIGN_DOUBLE",INT2NUM(ALIGN_DOUBLE));

    /* Document-const: ALIGN_SIZE_T
     *
     * The alignment size of a size_t
     */
    rb_define_const(rb_mDL, "ALIGN_SIZE_T", INT2NUM(ALIGN_OF(size_t)));

    /* Document-const: ALIGN_SSIZE_T
     *
     * The alignment size of a ssize_t
     */
    rb_define_const(rb_mDL, "ALIGN_SSIZE_T", INT2NUM(ALIGN_OF(size_t))); /* same as size_t */

    /* Document-const: ALIGN_PTRDIFF_T
     *
     * The alignment size of a ptrdiff_t
     */
    rb_define_const(rb_mDL, "ALIGN_PTRDIFF_T", INT2NUM(ALIGN_OF(ptrdiff_t)));

    /* Document-const: ALIGN_INTPTR_T
     *
     * The alignment size of a intptr_t
     */
    rb_define_const(rb_mDL, "ALIGN_INTPTR_T", INT2NUM(ALIGN_OF(intptr_t)));

    /* Document-const: ALIGN_UINTPTR_T
     *
     * The alignment size of a uintptr_t
     */
    rb_define_const(rb_mDL, "ALIGN_UINTPTR_T", INT2NUM(ALIGN_OF(uintptr_t)));

    /* Document-const: SIZEOF_VOIDP
     *
     * size of a void*
     */
    rb_define_const(rb_mDL, "SIZEOF_VOIDP", INT2NUM(sizeof(void*)));

    /* Document-const: SIZEOF_CHAR
     *
     * size of a char
     */
    rb_define_const(rb_mDL, "SIZEOF_CHAR",  INT2NUM(sizeof(char)));

    /* Document-const: SIZEOF_SHORT
     *
     * size of a short
     */
    rb_define_const(rb_mDL, "SIZEOF_SHORT", INT2NUM(sizeof(short)));

    /* Document-const: SIZEOF_INT
     *
     * size of an int
     */
    rb_define_const(rb_mDL, "SIZEOF_INT",   INT2NUM(sizeof(int)));

    /* Document-const: SIZEOF_LONG
     *
     * size of a long
     */
    rb_define_const(rb_mDL, "SIZEOF_LONG",  INT2NUM(sizeof(long)));

#if HAVE_LONG_LONG
    /* Document-const: SIZEOF_LONG_LONG
     *
     * size of a long long
     */
    rb_define_const(rb_mDL, "SIZEOF_LONG_LONG",  INT2NUM(sizeof(LONG_LONG)));
#endif

    /* Document-const: SIZEOF_FLOAT
     *
     * size of a float
     */
    rb_define_const(rb_mDL, "SIZEOF_FLOAT", INT2NUM(sizeof(float)));

    /* Document-const: SIZEOF_DOUBLE
     *
     * size of a double
     */
    rb_define_const(rb_mDL, "SIZEOF_DOUBLE",INT2NUM(sizeof(double)));

    /* Document-const: SIZEOF_SIZE_T
     *
     * size of a size_t
     */
    rb_define_const(rb_mDL, "SIZEOF_SIZE_T",  INT2NUM(sizeof(size_t)));

    /* Document-const: SIZEOF_SSIZE_T
     *
     * size of a ssize_t
     */
    rb_define_const(rb_mDL, "SIZEOF_SSIZE_T",  INT2NUM(sizeof(size_t))); /* same as size_t */

    /* Document-const: SIZEOF_PTRDIFF_T
     *
     * size of a ptrdiff_t
     */
    rb_define_const(rb_mDL, "SIZEOF_PTRDIFF_T",  INT2NUM(sizeof(ptrdiff_t)));

    /* Document-const: SIZEOF_INTPTR_T
     *
     * size of a intptr_t
     */
    rb_define_const(rb_mDL, "SIZEOF_INTPTR_T",  INT2NUM(sizeof(intptr_t)));

    /* Document-const: SIZEOF_UINTPTR_T
     *
     * size of a intptr_t
     */
    rb_define_const(rb_mDL, "SIZEOF_UINTPTR_T",  INT2NUM(sizeof(uintptr_t)));

    rb_define_module_function(rb_mDL, "dlwrap", rb_dl_value2ptr, 1);
    rb_define_module_function(rb_mDL, "dlunwrap", rb_dl_ptr2value, 1);

    rb_define_module_function(rb_mDL, "dlopen", rb_dl_dlopen, -1);
    rb_define_module_function(rb_mDL, "malloc", rb_dl_malloc, 1);
    rb_define_module_function(rb_mDL, "realloc", rb_dl_realloc, 2);
    rb_define_module_function(rb_mDL, "free", rb_dl_free, 1);

    /* Document-const: RUBY_FREE
     *
     * Address of the ruby_xfree() function
     */
    rb_define_const(rb_mDL, "RUBY_FREE", PTR2NUM(ruby_xfree));

    /* Document-const: BUILD_RUBY_PLATFORM
     *
     * Platform built against (i.e. "x86_64-linux", etc.)
     *
     * See also RUBY_PLATFORM
     */
    rb_define_const(rb_mDL, "BUILD_RUBY_PLATFORM", rb_str_new2(RUBY_PLATFORM));

    /* Document-const: BUILD_RUBY_VERSION
     *
     * Ruby Version built. (i.e. "1.9.3")
     *
     * See also RUBY_VERSION
     */
    rb_define_const(rb_mDL, "BUILD_RUBY_VERSION",  rb_str_new2(RUBY_VERSION));

    Init_dlhandle();
    Init_dlcfunc();
    Init_dlptr();
}
Exemplo n.º 22
0
/*
 * INIT
 */
void
Init_ossl_pkey()
{
#if 0
    mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
#endif

    /* Document-module: OpenSSL::PKey
     *
     * == Asymmetric Public Key Algorithms
     *
     * Asymmetric public key algorithms solve the problem of establishing and
     * sharing secret keys to en-/decrypt messages. The key in such an
     * algorithm consists of two parts: a public key that may be distributed
     * to others and a private key that needs to remain secret.
     *
     * Messages encrypted with a public key can only be encrypted by
     * recipients that are in possession of the associated private key.
     * Since public key algorithms are considerably slower than symmetric
     * key algorithms (cf. OpenSSL::Cipher) they are often used to establish
     * a symmetric key shared between two parties that are in possession of
     * each other's public key.
     *
     * Asymmetric algorithms offer a lot of nice features that are used in a
     * lot of different areas. A very common application is the creation and
     * validation of digital signatures. To sign a document, the signatory
     * generally uses a message digest algorithm (cf. OpenSSL::Digest) to
     * compute a digest of the document that is then encrypted (i.e. signed)
     * using the private key. Anyone in possession of the public key may then
     * verify the signature by computing the message digest of the original
     * document on their own, decrypting the signature using the signatory's
     * public key and comparing the result to the message digest they
     * previously computed. The signature is valid if and only if the
     * decrypted signature is equal to this message digest.
     *
     * The PKey module offers support for three popular public/private key
     * algorithms:
     * * RSA (OpenSSL::PKey::RSA)
     * * DSA (OpenSSL::PKey::DSA)
     * * Elliptic Curve Cryptography (OpenSSL::PKey::EC)
     * Each of these implementations is in fact a sub-class of the abstract
     * PKey class which offers the interface for supporting digital signatures
     * in the form of PKey#sign and PKey#verify.
     *
     * == Diffie-Hellman Key Exchange
     *
     * Finally PKey also features OpenSSL::PKey::DH, an implementation of
     * the Diffie-Hellman key exchange protocol based on discrete logarithms
     * in finite fields, the same basis that DSA is built on.
     * The Diffie-Hellman protocol can be used to exchange (symmetric) keys
     * over insecure channels without needing any prior joint knowledge
     * between the participating parties. As the security of DH demands
     * relatively long "public keys" (i.e. the part that is overtly
     * transmitted between participants) DH tends to be quite slow. If
     * security or speed is your primary concern, OpenSSL::PKey::EC offers
     * another implementation of the Diffie-Hellman protocol.
     *
     */
    mPKey = rb_define_module_under(mOSSL, "PKey");

    /* Document-class: OpenSSL::PKey::PKeyError
     *
     *Raised when errors occur during PKey#sign or PKey#verify.
     */
    ePKeyError = rb_define_class_under(mPKey, "PKeyError", eOSSLError);

    /* Document-class: OpenSSL::PKey::PKey
     *
     * An abstract class that bundles signature creation (PKey#sign) and
     * validation (PKey#verify) that is common to all implementations except
     * OpenSSL::PKey::DH
     * * OpenSSL::PKey::RSA
     * * OpenSSL::PKey::DSA
     * * OpenSSL::PKey::EC
     */
    cPKey = rb_define_class_under(mPKey, "PKey", rb_cObject);

    rb_define_module_function(mPKey, "read", ossl_pkey_new_from_data, -1);

    rb_define_alloc_func(cPKey, ossl_pkey_alloc);
    rb_define_method(cPKey, "initialize", ossl_pkey_initialize, 0);

    rb_define_method(cPKey, "sign", ossl_pkey_sign, 2);
    rb_define_method(cPKey, "verify", ossl_pkey_verify, 3);

    id_private_q = rb_intern("private?");

    /*
     * INIT rsa, dsa, dh, ec
     */
    Init_ossl_rsa();
    Init_ossl_dsa();
    Init_ossl_dh();
    Init_ossl_ec();
}
Exemplo n.º 23
0
Arquivo: class.c Projeto: amtep/ruby
/*!
 * Defines a global function
 * \param name    name of the function
 * \param func    the method body
 * \param argc    the number of parameters, or -1 or -2. see \ref defmethod.
 */
void
rb_define_global_function(const char *name, VALUE (*func)(ANYARGS), int argc)
{
    rb_define_module_function(rb_mKernel, name, func, argc);
}
Exemplo n.º 24
0
void Init_RRD(
    )
{
    mRRD = rb_define_module("RRD");
    rb_eRRDError = rb_define_class("RRDError", rb_eStandardError);

    rb_define_module_function(mRRD, "create", rb_rrd_create, -2);
    rb_define_module_function(mRRD, "dump", rb_rrd_dump, -2);
    rb_define_module_function(mRRD, "fetch", rb_rrd_fetch, -2);
    rb_define_module_function(mRRD, "graph", rb_rrd_graph, -2);
    rb_define_module_function(mRRD, "last", rb_rrd_last, -2);
    rb_define_module_function(mRRD, "resize", rb_rrd_resize, -2);
    rb_define_module_function(mRRD, "restore", rb_rrd_restore, -2);
    rb_define_module_function(mRRD, "tune", rb_rrd_tune, -2);
    rb_define_module_function(mRRD, "update", rb_rrd_update, -2);
    rb_define_module_function(mRRD, "flushcached", rb_rrd_flushcached, -2);
    rb_define_module_function(mRRD, "info", rb_rrd_info, -2);
    rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2);
    rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2);
    rb_define_module_function(mRRD, "xport", rb_rrd_xport, -2);
}
Exemplo n.º 25
0
void Init_talib()
{
  TA_Initialize();

  /*
   * Ruby extension for technical functions library api.
   */
  rb_mTaLib = rb_define_module("TaLib");

  rb_define_const(rb_mTaLib, "TA_Input_Price", INT2FIX(TA_Input_Price));
  rb_define_const(rb_mTaLib, "TA_Input_Real", INT2FIX(TA_Input_Real));
  rb_define_const(rb_mTaLib, "TA_Input_Integer", INT2FIX(TA_Input_Integer));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_OPEN", INT2FIX(TA_IN_PRICE_OPEN));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_HIGH", INT2FIX(TA_IN_PRICE_HIGH));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_LOW", INT2FIX(TA_IN_PRICE_LOW));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_CLOSE", INT2FIX(TA_IN_PRICE_CLOSE));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_VOLUME", INT2FIX(TA_IN_PRICE_VOLUME));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_OPENINTEREST", INT2FIX(TA_IN_PRICE_OPENINTEREST));
  rb_define_const(rb_mTaLib, "TA_IN_PRICE_TIMESTAMP", INT2FIX(TA_IN_PRICE_TIMESTAMP));
  rb_define_const(rb_mTaLib, "TA_OptInput_RealRange", INT2FIX(TA_OptInput_RealRange));
  rb_define_const(rb_mTaLib, "TA_OptInput_RealList", INT2FIX(TA_OptInput_RealList));
  rb_define_const(rb_mTaLib, "TA_OptInput_IntegerRange", INT2FIX(TA_OptInput_IntegerRange));
  rb_define_const(rb_mTaLib, "TA_OptInput_IntegerList", INT2FIX(TA_OptInput_IntegerList));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_PERCENT", INT2FIX(TA_OPTIN_IS_PERCENT));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_DEGREE", INT2FIX(TA_OPTIN_IS_DEGREE));
  rb_define_const(rb_mTaLib, "TA_OPTIN_IS_CURRENCY", INT2FIX(TA_OPTIN_IS_CURRENCY));
  rb_define_const(rb_mTaLib, "TA_OPTIN_ADVANCED", INT2FIX(TA_OPTIN_ADVANCED));
  rb_define_const(rb_mTaLib, "TA_Output_Real", INT2FIX(TA_Output_Real));
  rb_define_const(rb_mTaLib, "TA_Output_Integer", INT2FIX(TA_Output_Integer));
  rb_define_const(rb_mTaLib, "TA_OUT_LINE", INT2FIX(TA_OUT_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DOT_LINE", INT2FIX(TA_OUT_DOT_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DASH_LINE", INT2FIX(TA_OUT_DASH_LINE));
  rb_define_const(rb_mTaLib, "TA_OUT_DOT", INT2FIX(TA_OUT_DOT));
  rb_define_const(rb_mTaLib, "TA_OUT_HISTO", INT2FIX(TA_OUT_HISTO));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_BOOL", INT2FIX(TA_OUT_PATTERN_BOOL));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_BULL_BEAR", INT2FIX(TA_OUT_PATTERN_BULL_BEAR));
  rb_define_const(rb_mTaLib, "TA_OUT_PATTERN_STRENGTH", INT2FIX(TA_OUT_PATTERN_STRENGTH));
  rb_define_const(rb_mTaLib, "TA_OUT_POSITIVE", INT2FIX(TA_OUT_POSITIVE));
  rb_define_const(rb_mTaLib, "TA_OUT_NEGATIVE", INT2FIX(TA_OUT_NEGATIVE));
  rb_define_const(rb_mTaLib, "TA_OUT_ZERO", INT2FIX(TA_OUT_ZERO));
  rb_define_const(rb_mTaLib, "TA_OUT_UPPER_LIMIT", INT2FIX(TA_OUT_UPPER_LIMIT));
  rb_define_const(rb_mTaLib, "TA_OUT_LOWER_LIMIT", INT2FIX(TA_OUT_LOWER_LIMIT));
  rb_define_const(rb_mTaLib, "TA_MAType_SMA", INT2FIX((int)(TA_MAType_SMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_EMA", INT2FIX((int)(TA_MAType_EMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_WMA", INT2FIX((int)(TA_MAType_WMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_DEMA", INT2FIX((int)(TA_MAType_DEMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_TEMA", INT2FIX((int)(TA_MAType_TEMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_TRIMA", INT2FIX((int)(TA_MAType_TRIMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_KAMA", INT2FIX((int)(TA_MAType_KAMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_MAMA", INT2FIX((int)(TA_MAType_MAMA)));
  rb_define_const(rb_mTaLib, "TA_MAType_T3", INT2FIX((int)(TA_MAType_T3)));

  rb_struct_define("TA_RealRange", "min", "max", "precision", NULL);
  rb_struct_define("TA_IntegerRange", "min", "max", NULL );
  rb_struct_define("TA_RealDataPair", "value", "string", NULL );
  rb_struct_define("TA_IntegerDataPair", "value", "string", NULL );
  rb_struct_define("TA_RealList", "data", "nb_element", NULL );
  rb_struct_define("TA_IntegerList", "data", "nb_element", NULL );

  rb_sInParamInfo = rb_struct_define("TA_InputParameterInfo", "type", "param_name", "flags", NULL );
  rb_sOptInParamInfo = rb_struct_define("TA_OutInputParameterInfo", "type", "param_name", "flags", "display_name", "data_set", "default_value", "hint", "help_file", NULL );
  rb_sOutParamInfo = rb_struct_define("TA_OutputParameterInfo", "type", "param_name", "flags", NULL );

  /*
   * Class for technical analysis function.
   */
  rb_cTAFunction = rb_define_class_under(rb_mTaLib, "Function", rb_cObject);
  rb_define_alloc_func(rb_cTAFunction, ta_func_alloc);
  rb_define_method(rb_cTAFunction, "initialize", ta_func_initialize, 1);
  rb_define_attr(rb_cTAFunction, "result", 1, 1);

  rb_define_module_function( rb_cTAFunction, "groups",          ta_func_get_groups,             0 );
  rb_define_module_function( rb_cTAFunction, "functions", ta_func_get_functions,        0 );

  rb_define_method( rb_cTAFunction, "ins",  ta_func_get_input_count,                      0 );
  rb_define_method( rb_cTAFunction, "outs", ta_func_get_output_count,             0 );
  rb_define_method( rb_cTAFunction, "opts", ta_func_get_option_input_count, 0 );

  rb_define_method( rb_cTAFunction, "in",  ta_func_input_param_info,  1);
  rb_define_method( rb_cTAFunction, "opt", ta_func_option_param_info, 1);
  rb_define_method( rb_cTAFunction, "out", ta_func_output_param_info, 1);

  rb_define_method( rb_cTAFunction, "in_int",   ta_func_setup_in_integer, 2);
  rb_define_method( rb_cTAFunction, "in_real",  ta_func_setup_in_real,          2);
  rb_define_method( rb_cTAFunction, "in_price",   ta_func_setup_in_price, 7);
  rb_define_method( rb_cTAFunction, "opt_int",  ta_func_setup_opt_in_integer, 2);
  rb_define_method( rb_cTAFunction, "opt_real", ta_func_setup_opt_in_real,              2);
  rb_define_method( rb_cTAFunction, "out_int",  ta_func_setup_out_integer,              2);
  rb_define_method( rb_cTAFunction, "out_real", ta_func_setup_out_real,                         2);

  rb_define_method( rb_cTAFunction, "lookback", ta_func_lookback, 0);
  rb_define_method( rb_cTAFunction, "call", ta_func_call, 2);
}
Exemplo n.º 26
0
void Init_simple_hash(void) {
  rb_mFairySimpleHash = rb_define_module_under(rb_mFairy, "SimpleHash");
    
  rb_define_module_function(rb_mFairySimpleHash, "hash", rb_fairy_simple_hash, 1);
}
Exemplo n.º 27
0
/*
 * OpenSSL provides SSL, TLS and general purpose cryptography.  It wraps the
 * OpenSSL[http://www.openssl.org/] library.
 *
 * = Examples
 *
 * All examples assume you have loaded OpenSSL with:
 *
 *   require 'openssl'
 *
 * These examples build atop each other.  For example the key created in the
 * next is used in throughout these examples.
 *
 * == Keys
 *
 * === Creating a Key
 *
 * This example creates a 2048 bit RSA keypair and writes it to the current
 * directory.
 *
 *   key = OpenSSL::PKey::RSA.new 2048
 *
 *   open 'private_key.pem', 'w' do |io| io.write key.to_pem end
 *   open 'public_key.pem', 'w' do |io| io.write key.public_key.to_pem end
 *
 * === Exporting a Key
 *
 * Keys saved to disk without encryption are not secure as anyone who gets
 * ahold of the key may use it unless it is encrypted.  In order to securely
 * export a key you may export it with a pass phrase.
 *
 *   cipher = OpenSSL::Cipher::Cipher.new 'AES-128-CBC'
 *   pass_phrase = 'my secure pass phrase goes here'
 *
 *   key_secure = key.export cipher, pass_phrase
 *
 *   open 'private.secure.pem', 'w' do |io|
 *     io.write key_secure
 *   end
 *
 * OpenSSL::Cipher.ciphers returns a list of available ciphers.
 *
 * === Loading a Key
 *
 * A key can also be loaded from a file.
 *
 *   key2 = OpenSSL::PKey::RSA.new File.read 'private_key.pem'
 *   key2.public? # => true
 *
 * or
 *
 *   key3 = OpenSSL::PKey::RSA.new File.read 'public_key.pem'
 *   key3.private? # => false
 *
 * === Loading an Encrypted Key
 *
 * OpenSSL will prompt you for your pass phrase when loading an encrypted key.
 * If you will not be able to type in the pass phrase you may provide it when
 * loading the key:
 *
 *   key4_pem = File.read 'private.secure.pem'
 *   key4 = OpenSSL::PKey::RSA.new key4_pem, pass_phrase
 *
 * == RSA Encryption
 *
 * RSA provides ecryption and decryption using the public and private keys.
 * You can use a variety of padding methods depending upon the intended use of
 * encrypted data.
 *
 * === Encryption
 *
 * Documents encrypted with the public key can only be decrypted with the
 * private key.
 *
 *   public_encrypted = key.public_encrypt 'top secret document'
 *
 * Documents encrypted with the private key can only be decrypted with the
 * public key.
 *
 *   private_encrypted = key.private_encrypt 'public release document'
 *
 * === Decryption
 *
 * Use the opposite key type do decrypt the document
 *
 *   top_secret = key.public_decrypt public_encrypted
 *
 *   public_release = key.private_decrypt private_encrypted
 *
 * == PKCS #5 Password-based Encryption
 *
 * PKCS #5 is a password-based encryption standard documented at
 * RFC2898[http://www.ietf.org/rfc/rfc2898.txt].  It allows a short password or
 * passphrase to be used to create a secure encryption key.
 *
 * PKCS #5 uses a Cipher, a pass phrase and a salt to generate an encryption
 * key.
 *
 *   pass_phrase = 'my secure pass phrase goes here'
 *   salt = '8 octets'
 *
 * === Encryption
 *
 * First set up the cipher for encryption
 *
 *   encrypter = OpenSSL::Cipher::Cipher.new 'AES-128-CBC'
 *   encrypter.encrypt
 *   encrypter.pkcs5_keyivgen pass_phrase, salt
 *
 * Then pass the data you want to encrypt through
 *
 *   encrypted = encrypter.update 'top secret document'
 *   encrypted << encrypter.final
 *
 * === Decryption
 *
 * Use a new Cipher instance set up for decryption
 *
 *   decrypter = OpenSSL::Cipher::Cipher.new 'AES-128-CBC'
 *   decrypter.decrypt
 *   decrypter.pkcs5_keyivgen pass_phrase, salt
 *
 * Then pass the data you want to decrypt through
 *
 *   plain = decrypter.update encrypted
 *   plain << decrypter.final
 *
 * == X509 Certificates
 *
 * === Creating a Certificate
 *
 * This example creates a self-signed certificate using an RSA key and a SHA1
 * signature.
 *
 *   name = OpenSSL::X509::Name.parse 'CN=nobody/DC=example'
 *
 *   cert = OpenSSL::X509::Certificate.new
 *   cert.version = 2
 *   cert.serial = 0
 *   cert.not_before = Time.now
 *   cert.not_after = Time.now + 3600
 *
 *   cert.public_key = key.public_key
 *   cert.subject = name
 *
 * === Certificate Extensions
 *
 * You can add extensions to the certificate with
 * OpenSSL::SSL::ExtensionFactory to indicate the purpose of the certificate.
 *
 *   extension_factory = OpenSSL::X509::ExtensionFactory.new nil, cert
 *
 *   extension_factory.create_extension 'basicConstraints', 'CA:FALSE'
 *   extension_factory.create_extension 'keyUsage',
 *     'keyEncipherment,dataEncipherment,digitalSignature'
 *   extension_factory.create_extension 'subjectKeyIdentifier', 'hash'
 *
 * === Signing a Certificate
 *
 * To sign a certificate set the issuer and use OpenSSL::X509::Certificate#sign
 * with a digest algorithm.  This creates a self-signed cert because we're using
 * the same name and key to sign the certificate as was used to create the
 * certificate.
 *
 *   cert.issuer = name
 *   cert.sign key, OpenSSL::Digest::SHA1.new
 *
 *   open 'certificate.pem', 'w' do |io| io.write cert.to_pem end
 *
 * === Loading a Certificate
 *
 * Like a key, a cert can also be loaded from a file.
 *
 *   cert2 = OpenSSL::X509::Certificate.new File.read 'certificate.pem'
 *
 * === Verifying a Certificate
 *
 * Certificate#verify will return true when a certificate was signed with the
 * given public key.
 *
 *   raise 'certificate can not be verified' unless cert2.verify key
 *
 * == Certificate Authority
 *
 * A certificate authority (CA) is a trusted third party that allows you to
 * verify the ownership of unknown certificates.  The CA issues key signatures
 * that indicate it trusts the user of that key.  A user encountering the key
 * can verify the signature by using the CA's public key.
 *
 * === CA Key
 *
 * CA keys are valuable, so we encrypt and save it to disk and make sure it is
 * not readable by other users.
 *
 *   ca_key = OpenSSL::PKey::RSA.new 2048
 *
 *   cipher = OpenSSL::Cipher::Cipher.new 'AES-128-CBC'
 *
 *   open 'ca_key.pem', 'w', 0400 do |io|
 *     io.write key.export(cipher, pass_phrase)
 *   end
 *
 * === CA Certificate
 *
 * A CA certificate is created the same way we created a certificate above, but
 * with different extensions.
 *
 *   ca_name = OpenSSL::X509::Name.parse 'CN=ca/DC=example'
 *
 *   ca_cert = OpenSSL::X509::Certificate.new
 *   ca_cert.serial = 0
 *   ca_cert.version = 2
 *   ca_cert.not_before = Time.now
 *   ca_cert.not_after = Time.now + 86400
 *
 *   ca_cert.public_key = ca_key.public_key
 *   ca_cert.subject = ca_name
 *   ca_cert.issuer = ca_name
 *
 *   extension_factory = OpenSSL::X509::ExtensionFactory.new
 *   extension_factory.subject_certificate = ca_cert
 *   extension_factory.issuer_certificate = ca_cert
 *
 *   extension_factory.create_extension 'subjectKeyIdentifier', 'hash'
 *
 * This extension indicates the CA's key may be used as a CA.
 *
 *   extension_factory.create_extension 'basicConstraints', 'CA:TRUE', true
 *
 * This extension indicates the CA's key may be used to verify signatures on
 * both certificates and certificate revocations.
 *
 *   extension_factory.create_extension 'keyUsage', 'cRLSign,keyCertSign', true
 *
 * Root CA certificates are self-signed.
 *
 *   ca_cert.sign ca_key, OpenSSL::Digest::SHA1.new
 *
 * The CA certificate is saved to disk so it may be distributed to all the
 * users of the keys this CA will sign.
 *
 *   open 'ca_cert.pem', 'w' do |io|
 *     io.write ca_cert.to_pem
 *   end
 *
 * === Certificate Signing Request
 *
 * The CA signs keys through a Certificate Signing Request (CSR).  The CSR
 * contains the information necessary to identify the key.
 *
 *   csr = OpenSSL::X509::Request.new
 *   csr.version = 0
 *   csr.subject = name
 *   csr.public_key = key.public_key
 *   csr.sign key, OpenSSL::Digest::SHA1.new
 *
 * A CSR is saved to disk and sent to the CA for signing.
 *
 *   open 'csr.pem', 'w' do |io|
 *     io.write csr.to_pem
 *   end
 *
 * === Creating a Certificate from a CSR
 *
 * Upon receiving a CSR the CA will verify it before signing it.  A minimal
 * verification would be to check the CSR's signature.
 *
 *   csr = OpenSSL::X509::Request.new File.read 'csr.pem'
 *
 *   raise 'CSR can not be verified' unless csr.verify csr.public_key
 *
 * After verification a certificate is created, marked for various usages,
 * signed with the CA key and returned to the requester.
 *
 *   csr_cert = OpenSSL::X509::Certificate.new
 *   csr_cert.serial = 0
 *   csr_cert.version = 2
 *   csr_cert.not_before = Time.now
 *   csr_cert.not_after = Time.now + 600
 *
 *   csr_cert.subject = csr.subject
 *   csr_cert.public_key = csr.public_key
 *   csr_cert.issuer = ca_cert.subject
 *
 *   extension_factory = OpenSSL::X509::ExtensionFactory.new
 *   extension_factory.subject_certificate = csr_cert
 *   extension_factory.issuer_certificate = ca_cert
 *
 *   extension_factory.create_extension 'basicConstraints', 'CA:FALSE'
 *   extension_factory.create_extension 'keyUsage',
 *     'keyEncipherment,dataEncipherment,digitalSignature'
 *   extension_factory.create_extension 'subjectKeyIdentifier', 'hash'
 *
 *   csr_cert.sign ca_key, OpenSSL::Digest::SHA1.new
 *
 *   open 'csr_cert.pem', 'w' do |io|
 *     io.write csr_cert.to_pem
 *   end
 *
 * == SSL and TLS Connections
 *
 * Using our created key and certificate we can create an SSL or TLS connection.
 * An SSLContext is used to set up an SSL session.
 *
 *   context = OpenSSL::SSL::SSLContext.new
 *
 * === SSL Server
 *
 * An SSL server requires the certificate and private key to communicate
 * securely with its clients:
 *
 *   context.cert = cert
 *   context.key = key
 *
 * Then create an SSLServer with a TCP server socket and the context.  Use the
 * SSLServer like an ordinary TCP server.
 *
 *   require 'socket'
 *
 *   tcp_server = TCPServer.new 5000
 *   ssl_server = OpenSSL::SSL::SSLServer.new tcp_server, context
 *
 *   loop do
 *     ssl_connection = ssl_server.accept
 *
 *     data = connection.gets
 *
 *     response = "I got #{data.dump}"
 *     puts response
 *
 *     connection.puts "I got #{data.dump}"
 *     connection.close
 *   end
 *
 * === SSL client
 *
 * An SSL client is created with a TCP socket and the context.
 * SSLSocket#connect must be called to initiate the SSL handshake and start
 * encryption.  A key and certificate are not required for the client socket.
 *
 *   require 'socket'
 *
 *   tcp_client = TCPSocket.new 'localhost', 5000
 *   ssl_client = OpenSSL::SSL::SSLSocket.new client_socket, context
 *   ssl_client.connect
 *
 *   ssl_client.puts "hello server!"
 *   puts ssl_client.gets
 *
 * === Peer Verification
 *
 * An unverified SSL connection does not provide much security.  For enhanced
 * security the client or server can verify the certificate the of its peer.
 *
 * The client can be modified to verify the server's certificate against the
 * certificate authority's certificate:
 *
 *   context.ca_file = 'ca_cert.pem'
 *   context.verify_mode = OpenSSL::SSL::VERIFY_PEER
 *
 *   require 'socket'
 *
 *   tcp_client = TCPSocket.new 'localhost', 5000
 *   ssl_client = OpenSSL::SSL::SSLSocket.new client_socket, context
 *   ssl_client.connect
 *
 *   ssl_client.puts "hello server!"
 *   puts ssl_client.gets
 *
 * If the server certificate is invalid or <tt>context.ca_file</tt> is not set
 * when verifying peers an OpenSSL::SSL::SSLError will be raised.
 *
 */
void
Init_openssl()
{
    /*
     * Init timezone info
     */
#if 0
    tzset();
#endif

    /*
     * Init all digests, ciphers
     */
    /* CRYPTO_malloc_init(); */
    /* ENGINE_load_builtin_engines(); */
    OpenSSL_add_ssl_algorithms();
    OpenSSL_add_all_algorithms();
    ERR_load_crypto_strings();
    SSL_load_error_strings();

    /*
     * FIXME:
     * On unload do:
     */
#if 0
    CONF_modules_unload(1);
    destroy_ui_method();
    EVP_cleanup();
    ENGINE_cleanup();
    CRYPTO_cleanup_all_ex_data();
    ERR_remove_state(0);
    ERR_free_strings();
#endif

    /*
     * Init main module
     */
    mOSSL = rb_define_module("OpenSSL");

    /*
     * Constants
     */
    rb_define_const(mOSSL, "VERSION", rb_str_new2(OSSL_VERSION));
    rb_define_const(mOSSL, "OPENSSL_VERSION", rb_str_new2(OPENSSL_VERSION_TEXT));
    rb_define_const(mOSSL, "OPENSSL_VERSION_NUMBER", INT2NUM(OPENSSL_VERSION_NUMBER));

    /*
     * Generic error,
     * common for all classes under OpenSSL module
     */
    eOSSLError = rb_define_class_under(mOSSL,"OpenSSLError",rb_eStandardError);

    /*
     * Verify callback Proc index for ext-data
     */
    if ((ossl_verify_cb_idx = X509_STORE_CTX_get_ex_new_index(0, (void *)"ossl_verify_cb_idx", 0, 0, 0)) < 0)
        ossl_raise(eOSSLError, "X509_STORE_CTX_get_ex_new_index");

    /*
     * Init debug core
     */
    dOSSL = Qfalse;
    rb_define_module_function(mOSSL, "debug", ossl_debug_get, 0);
    rb_define_module_function(mOSSL, "debug=", ossl_debug_set, 1);
    rb_define_module_function(mOSSL, "errors", ossl_get_errors, 0);

    /*
     * Get ID of to_der
     */
    ossl_s_to_der = rb_intern("to_der");

    /*
     * Init components
     */
    Init_ossl_bn();
    Init_ossl_cipher();
    Init_ossl_config();
    Init_ossl_digest();
    Init_ossl_hmac();
    Init_ossl_ns_spki();
    Init_ossl_pkcs12();
    Init_ossl_pkcs7();
    Init_ossl_pkcs5();
    Init_ossl_pkey();
    Init_ossl_rand();
    Init_ossl_ssl();
    Init_ossl_x509();
    Init_ossl_ocsp();
    Init_ossl_engine();
    Init_ossl_asn1();
}
Exemplo n.º 28
0
void Init_rugged(void)
{
    rb_mRugged = rb_define_module("Rugged");

    /* Initialize the Error classes */
    {
        int i;

        rb_eRuggedError = rb_define_class_under(rb_mRugged, "Error", rb_eStandardError);

        rb_eRuggedErrors[0] = Qnil; /* 0 return value -- no exception */
        rb_eRuggedErrors[1] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[1], rb_eNoMemError);
        rb_eRuggedErrors[2] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[2], rb_eIOError);
        rb_eRuggedErrors[3] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[3], rb_eArgError);

        for (i = 4; i < RUGGED_ERROR_COUNT; ++i) {
            rb_eRuggedErrors[i] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[i], rb_eRuggedError);
        }
    }

    rb_define_module_function(rb_mRugged, "libgit2_version", rb_git_libgit2_version, 0);
    rb_define_module_function(rb_mRugged, "features", rb_git_features, 0);
    rb_define_module_function(rb_mRugged, "valid_full_oid?", rb_git_valid_full_oid, 1);
    rb_define_module_function(rb_mRugged, "hex_to_raw", rb_git_hex_to_raw, 1);
    rb_define_module_function(rb_mRugged, "raw_to_hex", rb_git_raw_to_hex, 1);
    rb_define_module_function(rb_mRugged, "minimize_oid", rb_git_minimize_oid, -1);
    rb_define_module_function(rb_mRugged, "prettify_message", rb_git_prettify_message, -1);
    rb_define_module_function(rb_mRugged, "__cache_usage__", rb_git_cache_usage, 0);

    Init_rugged_reference();
    Init_rugged_reference_collection();

    Init_rugged_object();
    Init_rugged_commit();
    Init_rugged_tree();
    Init_rugged_tag();
    Init_rugged_tag_collection();
    Init_rugged_blob();

    Init_rugged_index();
    Init_rugged_repo();
    Init_rugged_revwalk();
    Init_rugged_branch();
    Init_rugged_branch_collection();
    Init_rugged_config();
    Init_rugged_remote();
    Init_rugged_remote_collection();
    Init_rugged_notes();
    Init_rugged_settings();
    Init_rugged_submodule();
    Init_rugged_submodule_collection();
    Init_rugged_diff();
    Init_rugged_patch();
    Init_rugged_diff_delta();
    Init_rugged_diff_hunk();
    Init_rugged_diff_line();
    Init_rugged_blame();
    Init_rugged_cred();
    Init_rugged_backend();

    /*
     * Sort the repository contents in no particular ordering;
     * this sorting is arbitrary, implementation-specific
     * and subject to change at any time.
     * This is the default sorting for new walkers.
     */
    rb_define_const(rb_mRugged, "SORT_NONE", INT2FIX(GIT_SORT_NONE));

    /*
     * Sort the repository contents in topological order
     * (parents before children); this sorting mode
     * can be combined with time sorting.
     */
    rb_define_const(rb_mRugged, "SORT_TOPO", INT2FIX(GIT_SORT_TOPOLOGICAL));

    /*
     * Sort the repository contents by commit time;
     * this sorting mode can be combined with
     * topological sorting.
     */
    rb_define_const(rb_mRugged, "SORT_DATE", INT2FIX(GIT_SORT_TIME));

    /*
     * Iterate through the repository contents in reverse
     * order; this sorting mode can be combined with
     * any of the above.
     */
    rb_define_const(rb_mRugged, "SORT_REVERSE", INT2FIX(GIT_SORT_REVERSE));

    /* Initialize libgit2 */
    git_libgit2_init();

    /* Hook a global object to cleanup the library
     * on shutdown */
    rb_mShutdownHook = Data_Wrap_Struct(rb_cObject, NULL, &cleanup_cb, NULL);
    rb_global_variable(&rb_mShutdownHook);
}
Exemplo n.º 29
0
Arquivo: digest.c Projeto: sho-h/ruby
void
Init_digest(void)
{
    id_reset           = rb_intern("reset");
    id_update          = rb_intern("update");
    id_finish          = rb_intern("finish");
    id_digest          = rb_intern("digest");
    id_hexdigest       = rb_intern("hexdigest");
    id_digest_length   = rb_intern("digest_length");

    /*
     * module Digest
     */
    rb_mDigest = rb_define_module("Digest");

    /* module functions */
    rb_define_module_function(rb_mDigest, "hexencode", rb_digest_s_hexencode, 1);

    /*
     * module Digest::Instance
     */
    rb_mDigest_Instance = rb_define_module_under(rb_mDigest, "Instance");

    /* instance methods that should be overridden */
    rb_define_method(rb_mDigest_Instance, "update", rb_digest_instance_update, 1);
    rb_define_method(rb_mDigest_Instance, "<<", rb_digest_instance_update, 1);
    rb_define_private_method(rb_mDigest_Instance, "finish", rb_digest_instance_finish, 0);
    rb_define_method(rb_mDigest_Instance, "reset", rb_digest_instance_reset, 0);
    rb_define_method(rb_mDigest_Instance, "digest_length", rb_digest_instance_digest_length, 0);
    rb_define_method(rb_mDigest_Instance, "block_length", rb_digest_instance_block_length, 0);

    /* instance methods that may be overridden */
    rb_define_method(rb_mDigest_Instance, "==", rb_digest_instance_equal, 1);
    rb_define_method(rb_mDigest_Instance, "inspect", rb_digest_instance_inspect, 0);

    /* instance methods that need not usually be overridden */
    rb_define_method(rb_mDigest_Instance, "new", rb_digest_instance_new, 0);
    rb_define_method(rb_mDigest_Instance, "digest", rb_digest_instance_digest, -1);
    rb_define_method(rb_mDigest_Instance, "digest!", rb_digest_instance_digest_bang, 0);
    rb_define_method(rb_mDigest_Instance, "hexdigest", rb_digest_instance_hexdigest, -1);
    rb_define_method(rb_mDigest_Instance, "hexdigest!", rb_digest_instance_hexdigest_bang, 0);
    rb_define_method(rb_mDigest_Instance, "to_s", rb_digest_instance_to_s, 0);
    rb_define_method(rb_mDigest_Instance, "length", rb_digest_instance_length, 0);
    rb_define_method(rb_mDigest_Instance, "size", rb_digest_instance_length, 0);

    /*
     * class Digest::Class
     */
    rb_cDigest_Class = rb_define_class_under(rb_mDigest, "Class", rb_cObject);
    rb_define_method(rb_cDigest_Class, "initialize",  rb_digest_class_init, 0);
    rb_include_module(rb_cDigest_Class, rb_mDigest_Instance);

    /* class methods */
    rb_define_singleton_method(rb_cDigest_Class, "digest", rb_digest_class_s_digest, -1);
    rb_define_singleton_method(rb_cDigest_Class, "hexdigest", rb_digest_class_s_hexdigest, -1);

    id_metadata = rb_intern("metadata");

    /* class Digest::Base < Digest::Class */
    rb_cDigest_Base = rb_define_class_under(rb_mDigest, "Base", rb_cDigest_Class);

    rb_define_alloc_func(rb_cDigest_Base, rb_digest_base_alloc);

    rb_define_method(rb_cDigest_Base, "initialize_copy",  rb_digest_base_copy, 1);
    rb_define_method(rb_cDigest_Base, "reset", rb_digest_base_reset, 0);
    rb_define_method(rb_cDigest_Base, "update", rb_digest_base_update, 1);
    rb_define_method(rb_cDigest_Base, "<<", rb_digest_base_update, 1);
    rb_define_private_method(rb_cDigest_Base, "finish", rb_digest_base_finish, 0);
    rb_define_method(rb_cDigest_Base, "digest_length", rb_digest_base_digest_length, 0);
    rb_define_method(rb_cDigest_Base, "block_length", rb_digest_base_block_length, 0);
}
Exemplo n.º 30
0
void init_gmpbench_timing()
{
  mGMP = rb_define_module("GMP");
  rb_define_module_function(mGMP, "cputime", r_gmpmod_cputime, 0);
  rb_define_module_function(mGMP, "time", r_gmpmod_time, 0);
}