/src/rnp/src/lib/pass-provider.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2017 - 2019, [Ribose Inc](https://www.ribose.com). |
3 | | * All rights reserved. |
4 | | * |
5 | | * Redistribution and use in source and binary forms, with or without modification, |
6 | | * are permitted provided that the following conditions are met: |
7 | | * |
8 | | * 1. Redistributions of source code must retain the above copyright notice, |
9 | | * this list of conditions and the following disclaimer. |
10 | | * |
11 | | * 2. Redistributions in binary form must reproduce the above copyright notice, |
12 | | * this list of conditions and the following disclaimer in the documentation |
13 | | * and/or other materials provided with the distribution. |
14 | | * |
15 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
16 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
17 | | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
18 | | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
19 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
21 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
22 | | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
23 | | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
24 | | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | | */ |
26 | | #include "pass-provider.h" |
27 | | #include <stdio.h> |
28 | | #include <string.h> |
29 | | |
30 | | bool |
31 | | rnp_password_provider_string(const pgp_password_ctx_t *ctx, |
32 | | char * password, |
33 | | size_t password_size, |
34 | | void * userdata) |
35 | 0 | { |
36 | 0 | char *passc = (char *) userdata; |
37 | |
|
38 | 0 | if (!passc || strlen(passc) >= (password_size - 1)) { |
39 | 0 | return false; |
40 | 0 | } |
41 | | |
42 | 0 | strncpy(password, passc, password_size - 1); |
43 | 0 | return true; |
44 | 0 | } |
45 | | |
46 | | bool |
47 | | pgp_request_password(const pgp_password_provider_t *provider, |
48 | | const pgp_password_ctx_t * ctx, |
49 | | char * password, |
50 | | size_t password_size) |
51 | 73 | { |
52 | 73 | if (!provider || !provider->callback || !ctx || !password || !password_size) { |
53 | 0 | return false; |
54 | 0 | } |
55 | 73 | return provider->callback(ctx, password, password_size, provider->userdata); |
56 | 73 | } |