Re: [rust-dev] Casting *c_uchar to *c_char

2014-05-13 Thread Christophe Pedretti
So, if i understand correctly, using CString::new with 'false' as a
second argument implies :
- as you have no control on the lifetime underlying buffer, generally,
you have to as_str() and clone() the CString (the exception is when
you use immediately (right after creation) and only once the CString,
for example to display it)
- it better to write
value = unsafe { let tmp = CString::new(, false); if
tmp.is_not_null {tmp_str = tmp .as_str()}; tmp_str.clone() }
to avoid any misused of a possibly transient CString
than
let tmp = unsafe { CString::new(, false) };
value = if tmp.is_not_null {let tmp_str = tmp .as_str()}; tmp_str.clone() }

Thanks

2014-05-13 1:24 GMT+02:00 comex com...@gmail.com:
 On Mon, May 12, 2014 at 6:41 PM, Christophe Pedretti
 christophe.pedre...@gmail.com wrote:
 Another SQLite function, sqlite3_column_text, return a *c_uchar; so,
 tu use the CString new, which takes a *c_char as argument, i can cast
 CString::new(sqlite3_column_text(pStmt, column_index) as *i8, false)

 But is it correct ?

 Looks correct, but note that this doesn't copy any data by itself; if
 the original pointer becomes invalid, which happens in various
 situations documented by the SQLite API, so will the CString.
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Cryptography Library

2014-05-13 Thread Kevin Cantu
A bit of everything sounds like a good summary.

IIRC no cryptographer is working full-time to contribute to Rust, so there
are no plans to put more crypto than needed into standard libraries.

But serious libraries are more than welcome, and feedback would be great as
we get ever closer to stabilizing the language.  I've found the core devs
are *very* responsive.


Kevin




On Tue, May 6, 2014 at 2:43 PM, Brad Messer - messerb
mess...@clarkson.eduwrote:

  Is it fair to say that Rust could use a bit of everything then? I keep
 seeing a bunch of different protocols being named and that seems to be
 leading me to the prior conclusion. My thoughts coming into the work were
 protocols such as RSA and ECC, but I am more than willing to work on other
 protocols like AES and SHA.

  One more question, does Rust have a number theory package? I just want
 to know that should I implement some of the number theory based protocols,
 whether or not I also should develop a number theory library.

  Thanks everyone!

  Bradley Messer
  --
 *From:* Brad Messer - messerb
 *Sent:* Tuesday, May 06, 2014 1:14 PM
 *To:* Sean McArthur
 *Subject:* RE: [rust-dev] Cryptography Library

   Is it fair to say that Rust could use a bit of everything then? I keep
 seeing a bunch of different protocols being named and that seems to be
 leading me to the prior conclusion. My thoughts coming into the work were
 protocols such as RSA and ECC, but I am more than willing to work on other
 protocols like AES and SHA.

  One more question, does Rust have a number theory package? I just want
 to know that should I implement some of the number theory based protocols,
 whether or not I also should develop a number theory library.

  Thanks everyone!

  Bradley Messer
  --
 *From:* Rust-dev [rust-dev-boun...@mozilla.org] on behalf of Sean
 McArthur [smcart...@mozilla.com]
 *Sent:* Monday, May 05, 2014 2:37 PM
 *To:* Richo Healey; rust-dev
 *Subject:* Re: [rust-dev] Cryptography Library

  There's rust-crypto[1], which has quite a few implementations already.
 The issue isn't so much that Rust needs crypto code, is that it needs
 auditing of the code that exists.

  [1] https://github.com/DaGenix/rust-crypto

 ___
 Rust-dev mailing list
 Rust-dev@mozilla.org
 https://mail.mozilla.org/listinfo/rust-dev


___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Cryptography Library

2014-05-13 Thread Tony Arcieri
On Tue, May 13, 2014 at 1:52 AM, Kevin Cantu m...@kevincantu.org wrote:

 IIRC no cryptographer is working full-time to contribute to Rust, so there
 are no plans to put more crypto than needed into standard libraries.


It'd be great if Mozilla could loop in their security team on Rust
development *wink* *wink* *nudge* *nudge*

I look at efforts like PKIX and wonder why they're being done in C++
instead of Rust


 But serious libraries are more than welcome, and feedback would be great
 as we get ever closer to stabilizing the language.  I've found the core
 devs are *very* responsive.


The main thing I'd like to see in core Rust is something like a .NET
SecureString:

http://msdn.microsoft.com/en-us/library/system.security.securestring(v=vs.110).aspx

This is predicated on having a wrapping algorithm using a Key Encrypting
Key. So yeah, crypto ;)

As lower hanging fruit, how about a standard way to MemoryMap an mlocked
buffer with guard pages that are PROT_NONE?

I've been working on a SecretBuffer type for my library ClearCrypt, but
I'd really like to see something like that in Rust proper (even if it's
just flags for MemoryMap)

-- 
Tony Arcieri
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


[rust-dev] How to translate and use a void(*)(void*) in Rust ?

2014-05-13 Thread Christophe Pedretti
Hi all,

SQLITE is defining the following C function :
int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));

How to include it in an extern block ?
I have tried this
fn sqlite3_bind_text(pStmt : *mut(), iCol : c_int, value : *c_char, n
: c_int, f :  *proc(*())) - c_int;
(a pointer to a function taking a pointer as an argument)
i have also tried
fn sqlite3_bind_text(pStmt : *mut(), iCol : c_int, value : *c_char, n
: c_int, f :  *|*()|) - c_int;

In SQLITE, this argument can takes value SQLITE_STATIC or SQLITE_TRANSIENT
typedef void (*sqlite3_destructor_type)(void*);
#define SQLITE_STATIC  ((sqlite3_destructor_type)0)
#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)

for example, how to set this argument to SQLITE_STATIC in Rust ?

Thanks

-- 
Christophe
http://chris-pe.github.io/Rustic/
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] how to capture de-reference to ~int

2014-05-13 Thread Alex Crichton
The ~int type has since moved to Boxint, which will one day be a
library type with Deref implemented on it (currently it is implemented
by the compiler). Regardless, there's no need to implement the Deref
trait for the type today, the compiler already takes care of it.

For example, your code will compile without the deref trait:

fn main() {
let x: Boxint = box 3;
let y = *x;
println!({}, y);
}

The language only allows for one definition of each lang item, and
most lang items now reside in libcore, so you shouldn't have to define
them manually.

On Mon, May 12, 2014 at 11:50 AM, Noah Watkins jayh...@cs.ucsc.edu wrote:
 I am trying to capture the reference to type `~int` with the following
 code. I can change it to apply to bare `int` and it works fine.

 #[lang=deref]
 pub trait DerefResult {
 fn deref'a('a self) - 'a Result;
 }

 impl Deref~int for ~int {
 fn deref'a('a self) - 'a ~int {
 println!(deref caught);
 self
 }
 }

 fn main() {
   let x: ~int = 3;
   *x
 }

 Thanks,
 Noah
 ___
 Rust-dev mailing list
 Rust-dev@mozilla.org
 https://mail.mozilla.org/listinfo/rust-dev
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] how to capture de-reference to ~int

2014-05-13 Thread Noah Watkins
On Tue, May 13, 2014 at 2:19 PM, Alex Crichton a...@crichton.co wrote:
 The ~int type has since moved to Boxint, which will one day be a
 library type with Deref implemented on it (currently it is implemented
 by the compiler).

Thanks for the note. I'm using a slightly older version that doesn't
have BoxT, but it sounds like ~ is also implemented with the
compiler. I was actually looking into this because I was interested in
intercepting the deref (as well as allocate/free) for some distributed
shared-memory experiments. Some of the safety checks rust performs
simplifies the coherency requirements needed of the storage layer
(e.g. expensive locking).

-Noah


 On Mon, May 12, 2014 at 11:50 AM, Noah Watkins jayh...@cs.ucsc.edu wrote:
 I am trying to capture the reference to type `~int` with the following
 code. I can change it to apply to bare `int` and it works fine.

 #[lang=deref]
 pub trait DerefResult {
 fn deref'a('a self) - 'a Result;
 }

 impl Deref~int for ~int {
 fn deref'a('a self) - 'a ~int {
 println!(deref caught);
 self
 }
 }

 fn main() {
   let x: ~int = 3;
   *x
 }

 Thanks,
 Noah
 ___
 Rust-dev mailing list
 Rust-dev@mozilla.org
 https://mail.mozilla.org/listinfo/rust-dev
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev