Add self-test of base64 decode.
This commit is contained in:
parent
9d433d4f80
commit
8c8ba3bc20
@ -1,5 +1,6 @@
|
|||||||
/* Copyright (C) 2007 The Written Word, Inc. All rights reserved.
|
/* Copyright (C) 2007 The Written Word, Inc.
|
||||||
* Author: Simon Josefsson
|
* Copyright (C) 2008 Simon Josefsson
|
||||||
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms,
|
* Redistribution and use in source and binary forms,
|
||||||
* with or without modification, are permitted provided
|
* with or without modification, are permitted provided
|
||||||
@ -36,9 +37,36 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "libssh2.h"
|
#include "libssh2.h"
|
||||||
|
|
||||||
|
int test_libssh2_base64_decode (LIBSSH2_SESSION *session)
|
||||||
|
{
|
||||||
|
char *data;
|
||||||
|
unsigned int datalen;
|
||||||
|
const char *src = "Zm5vcmQ=";
|
||||||
|
unsigned int src_len = strlen (src);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = libssh2_base64_decode(session, &data, &datalen,
|
||||||
|
src, src_len);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (datalen != 5 || strcmp (data, "fnord") != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr,
|
||||||
|
"libssh2_base64_decode() failed (%d, %.*s)\n",
|
||||||
|
datalen, datalen, data);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free (data);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
@ -50,6 +78,8 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_libssh2_base64_decode (session);
|
||||||
|
|
||||||
libssh2_session_free(session);
|
libssh2_session_free(session);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user