libopensc: new exported function to reverse memory buffer

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5516 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
vtarasov 2011-05-29 17:47:54 +00:00
parent 4f9924eae8
commit dce63c8bfc
3 changed files with 19 additions and 0 deletions

View File

@ -117,6 +117,7 @@ sc_lock
sc_logout
sc_make_cache_dir
sc_mem_clear
sc_mem_reverse
sc_path_print
sc_path_set
sc_pin_cmd

View File

@ -1149,6 +1149,7 @@ int sc_base64_decode(const char *in, u8 *out, size_t outlen);
*/
void sc_mem_clear(void *ptr, size_t len);
void *sc_mem_alloc_secure(size_t len);
int sc_mem_reverse(unsigned char *buf, size_t len);
int sc_get_cache_dir(sc_context_t *ctx, char *buf, size_t bufsize);
int sc_make_cache_dir(sc_context_t *ctx);

View File

@ -727,6 +727,23 @@ void sc_mem_clear(void *ptr, size_t len)
#endif
}
int sc_mem_reverse(unsigned char *buf, size_t len)
{
unsigned char ch;
size_t ii;
if (!buf || !len)
return SC_ERROR_INVALID_ARGUMENTS;
for (ii = 0; ii < len / 2; ii++) {
ch = *(buf + ii);
*(buf + ii) = *(buf + len - 1 - ii);
*(buf + len - 1 - ii) = ch;
}
return 0;
}
static int
sc_remote_apdu_allocate(struct sc_remote_data *rdata,
struct sc_remote_apdu **new_rapdu)