Skip to content

Commit

Permalink
(add-start-tls) updated example code in the readme, removed references
Browse files Browse the repository at this point in the history
to try!
  • Loading branch information
JedimEmO committed Jan 10, 2020
1 parent 263a5c2 commit a1ebc6d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ use openldap::*;
use openldap::errors::*;

fn some_ldap_function(ldap_uri: &str, ldap_user: &str, ldap_pass: &str) -> Result<(), LDAPError> {

let ldap = try!(RustLDAP::new(ldap_uri));
let ldap = RustLDAP::new(ldap_uri).unwrap();

ldap.set_option(codes::options::LDAP_OPT_PROTOCOL_VERSION,
&codes::versions::LDAP_VERSION3);

ldap.set_option(codes::options::LDAP_OPT_X_TLS_REQUIRE_CERT,
&codes::options::LDAP_OPT_X_TLS_DEMAND);

try!(ldap.simple_bind(ldap_user, ldap_pass));
ldap.simple_bind(ldap_user, ldap_pass).unwrap();

// Returns a LDAPResponse, a.k.a. Vec<HashMap<String,Vec<String>>>.
let _ = ldap.simple_search("CN=Stephen,OU=People,DC=Earth",
Expand All @@ -49,22 +48,24 @@ network. See https://linux.die.net/man/3/ldap_start_tls_s for more information

```rust
fn some_ldap_function(ldap_uri: &str, ldap_user: &str, ldap_pass: &str) -> Result<(), LDAPError> {
let ldap = try!(RustLDAP::new(ldap_uri));
let ldap = RustLDAP::new(ldap_uri).unwrap();

ldap.set_option(codes::options::LDAP_OPT_PROTOCOL_VERSION,
&codes::versions::LDAP_VERSION3);

ldap.set_option(codes::options::LDAP_OPT_X_TLS_REQUIRE_CERT,
&codes::options::LDAP_OPT_X_TLS_DEMAND);
ldap.set_option(openldap::codes::options::LDAP_OPT_X_TLS_NEWCTX, &0);

ldap.start_tls(None, None);

try!(ldap.simple_bind(ldap_user, ldap_pass));
ldap.simple_bind(ldap_user, ldap_pass).unwrap();

Ok(())
}

```
When performing an operation that can fail, use the `try!` macro. On failure,
an `openldap::errors::LDAPError` will be returned that includes a detailed
On failure, an `openldap::errors::LDAPError` will be returned that includes a detailed
message from the native OpenLDAP library.

## contributing
Expand Down

0 comments on commit a1ebc6d

Please sign in to comment.