Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nettle
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Brian Smith
nettle
Commits
86fdb2ce
Commit
86fdb2ce
authored
Apr 26, 2013
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use size_t rather than unsigned for base16, base64, nettle_bufer and sexp related functions.
parent
eb7c996e
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
173 additions
and
164 deletions
+173
-164
base16-decode.c
base16-decode.c
+5
-5
base16-encode.c
base16-encode.c
+3
-3
base16-meta.c
base16-meta.c
+18
-11
base16.h
base16.h
+3
-3
base64-decode.c
base64-decode.c
+4
-4
base64-encode.c
base64-encode.c
+8
-8
base64-meta.c
base64-meta.c
+6
-4
base64.h
base64.h
+7
-7
buffer.c
buffer.c
+5
-5
buffer.h
buffer.h
+6
-6
examples/base16dec.c
examples/base16dec.c
+25
-25
examples/base64dec.c
examples/base64dec.c
+1
-1
nettle-types.h
nettle-types.h
+8
-8
sexp-format.c
sexp-format.c
+20
-20
sexp-transport-format.c
sexp-transport-format.c
+6
-6
sexp-transport.c
sexp-transport.c
+5
-5
sexp.c
sexp.c
+5
-5
sexp.h
sexp.h
+15
-15
testsuite/base64-test.c
testsuite/base64-test.c
+1
-1
testsuite/sexp-format-test.c
testsuite/sexp-format-test.c
+3
-3
testsuite/testutils.c
testsuite/testutils.c
+2
-2
tools/input.c
tools/input.c
+1
-1
tools/pkcs1-conv.c
tools/pkcs1-conv.c
+16
-16
No files found.
base16-decode.c
View file @
86fdb2ce
...
@@ -93,17 +93,17 @@ base16_decode_single(struct base16_decode_ctx *ctx,
...
@@ -93,17 +93,17 @@ base16_decode_single(struct base16_decode_ctx *ctx,
int
int
base16_decode_update
(
struct
base16_decode_ctx
*
ctx
,
base16_decode_update
(
struct
base16_decode_ctx
*
ctx
,
unsigned
*
dst_length
,
size_t
*
dst_length
,
uint8_t
*
dst
,
uint8_t
*
dst
,
unsigned
src_length
,
size_t
src_length
,
const
uint8_t
*
src
)
const
uint8_t
*
src
)
{
{
unsigned
done
;
size_t
done
;
unsigned
i
;
size_t
i
;
assert
(
*
dst_length
>=
BASE16_DECODE_LENGTH
(
src_length
));
assert
(
*
dst_length
>=
BASE16_DECODE_LENGTH
(
src_length
));
for
(
i
=
0
,
done
=
0
;
i
<
src_length
;
i
++
)
for
(
i
=
done
=
0
;
i
<
src_length
;
i
++
)
switch
(
base16_decode_single
(
ctx
,
dst
+
done
,
src
[
i
]))
switch
(
base16_decode_single
(
ctx
,
dst
+
done
,
src
[
i
]))
{
{
case
-
1
:
case
-
1
:
...
...
base16-encode.c
View file @
86fdb2ce
...
@@ -47,11 +47,11 @@ base16_encode_single(uint8_t *dst,
...
@@ -47,11 +47,11 @@ base16_encode_single(uint8_t *dst,
/* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
/* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
void
void
base16_encode_update
(
uint8_t
*
dst
,
base16_encode_update
(
uint8_t
*
dst
,
unsigned
length
,
size_t
length
,
const
uint8_t
*
src
)
const
uint8_t
*
src
)
{
{
unsigned
i
;
size_t
i
;
for
(
i
=
0
,
dst
;
i
<
length
;
i
++
,
dst
+=
2
)
for
(
i
=
0
;
i
<
length
;
i
++
,
dst
+=
2
)
base16_encode_single
(
dst
,
src
[
i
]);
base16_encode_single
(
dst
,
src
[
i
]);
}
}
base16-meta.c
View file @
86fdb2ce
...
@@ -29,25 +29,29 @@
...
@@ -29,25 +29,29 @@
#include "base16.h"
#include "base16.h"
/* Same as the macros with the same name */
/* Same as the macros with the same name */
static
unsigned
static
nettle_armor_length_func
base16_encode_length
;
base16_encode_length
(
unsigned
length
)
static
size_t
base16_encode_length
(
size_t
length
)
{
{
return
BASE16_ENCODE_LENGTH
(
length
);
return
BASE16_ENCODE_LENGTH
(
length
);
}
}
static
unsigned
static
nettle_armor_length_func
base16_decode_length
;
base16_decode_length
(
unsigned
length
)
static
size_t
base16_decode_length
(
size_t
length
)
{
{
return
BASE16_DECODE_LENGTH
(
length
);
return
BASE16_DECODE_LENGTH
(
length
);
}
}
static
nettle_armor_init_func
base16_encode_init
;
static
void
static
void
base16_encode_init
(
void
*
ctx
)
base16_encode_init
(
void
*
ctx
UNUSED
)
{
(
void
)
ctx
;
}
{
}
static
unsigned
static
nettle_armor_encode_update_func
base16_encode_update_wrapper
;
static
size_t
base16_encode_update_wrapper
(
void
*
ctx
UNUSED
,
uint8_t
*
dst
,
base16_encode_update_wrapper
(
void
*
ctx
UNUSED
,
uint8_t
*
dst
,
unsigned
length
,
const
uint8_t
*
src
)
size_t
length
,
const
uint8_t
*
src
)
{
{
base16_encode_update
(
dst
,
length
,
src
);
base16_encode_update
(
dst
,
length
,
src
);
return
BASE16_ENCODE_LENGTH
(
length
);
return
BASE16_ENCODE_LENGTH
(
length
);
...
@@ -56,9 +60,12 @@ base16_encode_update_wrapper(void *ctx UNUSED, uint8_t *dst,
...
@@ -56,9 +60,12 @@ base16_encode_update_wrapper(void *ctx UNUSED, uint8_t *dst,
#undef base16_encode_update
#undef base16_encode_update
#define base16_encode_update base16_encode_update_wrapper
#define base16_encode_update base16_encode_update_wrapper
static
unsigned
static
nettle_armor_encode_final_func
base16_encode_final
;
base16_encode_final
(
void
*
ctx
,
uint8_t
*
dst
)
static
size_t
{
(
void
)
ctx
;
(
void
)
dst
;
return
0
;
}
base16_encode_final
(
void
*
ctx
UNUSED
,
uint8_t
*
dst
UNUSED
)
{
return
0
;
}
#define BASE16_ENCODE_FINAL_LENGTH 0
#define BASE16_ENCODE_FINAL_LENGTH 0
...
...
base16.h
View file @
86fdb2ce
...
@@ -54,7 +54,7 @@ base16_encode_single(uint8_t *dst,
...
@@ -54,7 +54,7 @@ base16_encode_single(uint8_t *dst,
/* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
/* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
void
void
base16_encode_update
(
uint8_t
*
dst
,
base16_encode_update
(
uint8_t
*
dst
,
unsigned
length
,
size_t
length
,
const
uint8_t
*
src
);
const
uint8_t
*
src
);
...
@@ -90,9 +90,9 @@ base16_decode_single(struct base16_decode_ctx *ctx,
...
@@ -90,9 +90,9 @@ base16_decode_single(struct base16_decode_ctx *ctx,
* too small. FIXME: Return some error instead? */
* too small. FIXME: Return some error instead? */
int
int
base16_decode_update
(
struct
base16_decode_ctx
*
ctx
,
base16_decode_update
(
struct
base16_decode_ctx
*
ctx
,
unsigned
*
dst_length
,
size_t
*
dst_length
,
uint8_t
*
dst
,
uint8_t
*
dst
,
unsigned
src_length
,
size_t
src_length
,
const
uint8_t
*
src
);
const
uint8_t
*
src
);
/* Returns 1 on success. */
/* Returns 1 on success. */
...
...
base64-decode.c
View file @
86fdb2ce
...
@@ -114,13 +114,13 @@ base64_decode_single(struct base64_decode_ctx *ctx,
...
@@ -114,13 +114,13 @@ base64_decode_single(struct base64_decode_ctx *ctx,
int
int
base64_decode_update
(
struct
base64_decode_ctx
*
ctx
,
base64_decode_update
(
struct
base64_decode_ctx
*
ctx
,
unsigned
*
dst_length
,
size_t
*
dst_length
,
uint8_t
*
dst
,
uint8_t
*
dst
,
unsigned
src_length
,
size_t
src_length
,
const
uint8_t
*
src
)
const
uint8_t
*
src
)
{
{
unsigned
done
;
size_t
done
;
unsigned
i
;
size_t
i
;
assert
(
*
dst_length
>=
BASE64_DECODE_LENGTH
(
src_length
));
assert
(
*
dst_length
>=
BASE64_DECODE_LENGTH
(
src_length
));
...
...
base64-encode.c
View file @
86fdb2ce
...
@@ -39,7 +39,7 @@ static const uint8_t encode_table[64] =
...
@@ -39,7 +39,7 @@ static const uint8_t encode_table[64] =
#define ENCODE(x) (encode_table[0x3F & (x)])
#define ENCODE(x) (encode_table[0x3F & (x)])
void
void
base64_encode_raw
(
uint8_t
*
dst
,
unsigned
length
,
const
uint8_t
*
src
)
base64_encode_raw
(
uint8_t
*
dst
,
size_t
length
,
const
uint8_t
*
src
)
{
{
const
uint8_t
*
in
=
src
+
length
;
const
uint8_t
*
in
=
src
+
length
;
uint8_t
*
out
=
dst
+
BASE64_ENCODE_RAW_LENGTH
(
length
);
uint8_t
*
out
=
dst
+
BASE64_ENCODE_RAW_LENGTH
(
length
);
...
@@ -140,7 +140,7 @@ base64_encode_init(struct base64_encode_ctx *ctx)
...
@@ -140,7 +140,7 @@ base64_encode_init(struct base64_encode_ctx *ctx)
}
}
/* Encodes a single byte. */
/* Encodes a single byte. */
unsigned
size_t
base64_encode_single
(
struct
base64_encode_ctx
*
ctx
,
base64_encode_single
(
struct
base64_encode_ctx
*
ctx
,
uint8_t
*
dst
,
uint8_t
*
dst
,
uint8_t
src
)
uint8_t
src
)
...
@@ -165,16 +165,16 @@ base64_encode_single(struct base64_encode_ctx *ctx,
...
@@ -165,16 +165,16 @@ base64_encode_single(struct base64_encode_ctx *ctx,
/* Returns the number of output characters. DST should point to an
/* Returns the number of output characters. DST should point to an
* area of size at least BASE64_ENCODE_LENGTH(length). */
* area of size at least BASE64_ENCODE_LENGTH(length). */
unsigned
size_t
base64_encode_update
(
struct
base64_encode_ctx
*
ctx
,
base64_encode_update
(
struct
base64_encode_ctx
*
ctx
,
uint8_t
*
dst
,
uint8_t
*
dst
,
unsigned
length
,
size_t
length
,
const
uint8_t
*
src
)
const
uint8_t
*
src
)
{
{
unsigned
done
=
0
;
size_t
done
=
0
;
unsigned
left
=
length
;
size_t
left
=
length
;
unsigned
left_over
;
unsigned
left_over
;
unsigned
bulk
;
size_t
bulk
;
while
(
ctx
->
bits
&&
left
)
while
(
ctx
->
bits
&&
left
)
{
{
...
@@ -208,7 +208,7 @@ base64_encode_update(struct base64_encode_ctx *ctx,
...
@@ -208,7 +208,7 @@ base64_encode_update(struct base64_encode_ctx *ctx,
/* DST should point to an area of size at least
/* DST should point to an area of size at least
* BASE64_ENCODE_FINAL_SIZE */
* BASE64_ENCODE_FINAL_SIZE */
unsigned
size_t
base64_encode_final
(
struct
base64_encode_ctx
*
ctx
,
base64_encode_final
(
struct
base64_encode_ctx
*
ctx
,
uint8_t
*
dst
)
uint8_t
*
dst
)
{
{
...
...
base64-meta.c
View file @
86fdb2ce
...
@@ -29,14 +29,16 @@
...
@@ -29,14 +29,16 @@
#include "base64.h"
#include "base64.h"
/* Same as the macros with the same name */
/* Same as the macros with the same name */
static
unsigned
static
nettle_armor_length_func
base64_encode_length
;
base64_encode_length
(
unsigned
length
)
static
size_t
base64_encode_length
(
size_t
length
)
{
{
return
BASE64_ENCODE_LENGTH
(
length
);
return
BASE64_ENCODE_LENGTH
(
length
);
}
}
static
unsigned
static
nettle_armor_length_func
base64_decode_length
;
base64_decode_length
(
unsigned
length
)
static
size_t
base64_decode_length
(
size_t
length
)
{
{
return
BASE64_DECODE_LENGTH
(
length
);
return
BASE64_DECODE_LENGTH
(
length
);
}
}
...
...
base64.h
View file @
86fdb2ce
...
@@ -71,22 +71,22 @@ void
...
@@ -71,22 +71,22 @@ void
base64_encode_init
(
struct
base64_encode_ctx
*
ctx
);
base64_encode_init
(
struct
base64_encode_ctx
*
ctx
);
/* Encodes a single byte. Returns amount of output (always 1 or 2). */
/* Encodes a single byte. Returns amount of output (always 1 or 2). */
unsigned
size_t
base64_encode_single
(
struct
base64_encode_ctx
*
ctx
,
base64_encode_single
(
struct
base64_encode_ctx
*
ctx
,
uint8_t
*
dst
,
uint8_t
*
dst
,
uint8_t
src
);
uint8_t
src
);
/* Returns the number of output characters. DST should point to an
/* Returns the number of output characters. DST should point to an
* area of size at least BASE64_ENCODE_LENGTH(length). */
* area of size at least BASE64_ENCODE_LENGTH(length). */
unsigned
size_t
base64_encode_update
(
struct
base64_encode_ctx
*
ctx
,
base64_encode_update
(
struct
base64_encode_ctx
*
ctx
,
uint8_t
*
dst
,
uint8_t
*
dst
,
unsigned
length
,
size_t
length
,
const
uint8_t
*
src
);
const
uint8_t
*
src
);
/* DST should point to an area of size at least
/* DST should point to an area of size at least
* BASE64_ENCODE_FINAL_LENGTH */
* BASE64_ENCODE_FINAL_LENGTH */
unsigned
size_t
base64_encode_final
(
struct
base64_encode_ctx
*
ctx
,
base64_encode_final
(
struct
base64_encode_ctx
*
ctx
,
uint8_t
*
dst
);
uint8_t
*
dst
);
...
@@ -96,7 +96,7 @@ base64_encode_final(struct base64_encode_ctx *ctx,
...
@@ -96,7 +96,7 @@ base64_encode_final(struct base64_encode_ctx *ctx,
* Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
* Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
* Supports overlapped operation, if src <= dst. */
* Supports overlapped operation, if src <= dst. */
void
void
base64_encode_raw
(
uint8_t
*
dst
,
unsigned
length
,
const
uint8_t
*
src
);
base64_encode_raw
(
uint8_t
*
dst
,
size_t
length
,
const
uint8_t
*
src
);
void
void
base64_encode_group
(
uint8_t
*
dst
,
uint32_t
group
);
base64_encode_group
(
uint8_t
*
dst
,
uint32_t
group
);
...
@@ -137,9 +137,9 @@ base64_decode_single(struct base64_decode_ctx *ctx,
...
@@ -137,9 +137,9 @@ base64_decode_single(struct base64_decode_ctx *ctx,
* too small. FIXME: Return some error instead? */
* too small. FIXME: Return some error instead? */
int
int
base64_decode_update
(
struct
base64_decode_ctx
*
ctx
,
base64_decode_update
(
struct
base64_decode_ctx
*
ctx
,
unsigned
*
dst_length
,
size_t
*
dst_length
,
uint8_t
*
dst
,
uint8_t
*
dst
,
unsigned
src_length
,
size_t
src_length
,
const
uint8_t
*
src
);
const
uint8_t
*
src
);
/* Returns 1 on success. */
/* Returns 1 on success. */
...
...
buffer.c
View file @
86fdb2ce
...
@@ -35,13 +35,13 @@
...
@@ -35,13 +35,13 @@
int
int
nettle_buffer_grow
(
struct
nettle_buffer
*
buffer
,
nettle_buffer_grow
(
struct
nettle_buffer
*
buffer
,
unsigned
length
)
size_t
length
)
{
{
assert
(
buffer
->
size
<=
buffer
->
alloc
);
assert
(
buffer
->
size
<=
buffer
->
alloc
);
if
(
buffer
->
size
+
length
>
buffer
->
alloc
)
if
(
buffer
->
size
+
length
>
buffer
->
alloc
)
{
{
unsigned
alloc
;
size_t
alloc
;
uint8_t
*
p
;
uint8_t
*
p
;
if
(
!
buffer
->
realloc
)
if
(
!
buffer
->
realloc
)
...
@@ -72,7 +72,7 @@ nettle_buffer_init_realloc(struct nettle_buffer *buffer,
...
@@ -72,7 +72,7 @@ nettle_buffer_init_realloc(struct nettle_buffer *buffer,
void
void
nettle_buffer_init_size
(
struct
nettle_buffer
*
buffer
,
nettle_buffer_init_size
(
struct
nettle_buffer
*
buffer
,
unsigned
length
,
uint8_t
*
space
)
size_t
length
,
uint8_t
*
space
)
{
{
buffer
->
contents
=
space
;
buffer
->
contents
=
space
;
buffer
->
alloc
=
length
;
buffer
->
alloc
=
length
;
...
@@ -100,7 +100,7 @@ nettle_buffer_reset(struct nettle_buffer *buffer)
...
@@ -100,7 +100,7 @@ nettle_buffer_reset(struct nettle_buffer *buffer)
uint8_t
*
uint8_t
*
nettle_buffer_space
(
struct
nettle_buffer
*
buffer
,
nettle_buffer_space
(
struct
nettle_buffer
*
buffer
,
unsigned
length
)
size_t
length
)
{
{
uint8_t
*
p
;
uint8_t
*
p
;
...
@@ -114,7 +114,7 @@ nettle_buffer_space(struct nettle_buffer *buffer,
...
@@ -114,7 +114,7 @@ nettle_buffer_space(struct nettle_buffer *buffer,
int
int
nettle_buffer_write
(
struct
nettle_buffer
*
buffer
,
nettle_buffer_write
(
struct
nettle_buffer
*
buffer
,
unsigned
length
,
const
uint8_t
*
data
)
size_t
length
,
const
uint8_t
*
data
)
{
{
uint8_t
*
p
=
nettle_buffer_space
(
buffer
,
length
);
uint8_t
*
p
=
nettle_buffer_space
(
buffer
,
length
);
if
(
p
)
if
(
p
)
...
...
buffer.h
View file @
86fdb2ce
...
@@ -36,13 +36,13 @@ struct nettle_buffer
...
@@ -36,13 +36,13 @@ struct nettle_buffer
{
{
uint8_t
*
contents
;
uint8_t
*
contents
;
/* Allocated size */
/* Allocated size */
unsigned
alloc
;
size_t
alloc
;
void
*
realloc_ctx
;
void
*
realloc_ctx
;
nettle_realloc_func
*
realloc
;
nettle_realloc_func
*
realloc
;
/* Current size */
/* Current size */
unsigned
size
;
size_t
size
;
};
};
/* Initializes a buffer that uses plain realloc */
/* Initializes a buffer that uses plain realloc */
...
@@ -57,7 +57,7 @@ nettle_buffer_init_realloc(struct nettle_buffer *buffer,
...
@@ -57,7 +57,7 @@ nettle_buffer_init_realloc(struct nettle_buffer *buffer,
/* Initializes a buffer of fix size */
/* Initializes a buffer of fix size */
void
void
nettle_buffer_init_size
(
struct
nettle_buffer
*
buffer
,
nettle_buffer_init_size
(
struct
nettle_buffer
*
buffer
,
unsigned
length
,
uint8_t
*
space
);
size_t
length
,
uint8_t
*
space
);
void
void
nettle_buffer_clear
(
struct
nettle_buffer
*
buffer
);
nettle_buffer_clear
(
struct
nettle_buffer
*
buffer
);
...
@@ -68,7 +68,7 @@ nettle_buffer_reset(struct nettle_buffer *buffer);
...
@@ -68,7 +68,7 @@ nettle_buffer_reset(struct nettle_buffer *buffer);
int
int
nettle_buffer_grow
(
struct
nettle_buffer
*
buffer
,
nettle_buffer_grow
(
struct
nettle_buffer
*
buffer
,
unsigned
length
);
size_t
length
);
#define NETTLE_BUFFER_PUTC(buffer, c) \
#define NETTLE_BUFFER_PUTC(buffer, c) \
( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
...
@@ -76,7 +76,7 @@ nettle_buffer_grow(struct nettle_buffer *buffer,
...
@@ -76,7 +76,7 @@ nettle_buffer_grow(struct nettle_buffer *buffer,
int
int
nettle_buffer_write
(
struct
nettle_buffer
*
buffer
,
nettle_buffer_write
(
struct
nettle_buffer
*
buffer
,
unsigned
length
,
const
uint8_t
*
data
);
size_t
length
,
const
uint8_t
*
data
);
/* Like nettle_buffer_write, but instead of copying data to the
/* Like nettle_buffer_write, but instead of copying data to the
* buffer, it returns a pointer to the area where the caller can copy
* buffer, it returns a pointer to the area where the caller can copy
...
@@ -84,7 +84,7 @@ nettle_buffer_write(struct nettle_buffer *buffer,
...
@@ -84,7 +84,7 @@ nettle_buffer_write(struct nettle_buffer *buffer,
* reallocate the buffer. */
* reallocate the buffer. */
uint8_t
*
uint8_t
*
nettle_buffer_space
(
struct
nettle_buffer
*
buffer
,
nettle_buffer_space
(
struct
nettle_buffer
*
buffer
,
unsigned
length
);
size_t
length
);
/* Copy the contents of SRC to the end of DST. */
/* Copy the contents of SRC to the end of DST. */
int
int
...
...
examples/base16dec.c
View file @
86fdb2ce
...
@@ -65,7 +65,7 @@ main(int argc UNUSED, char **argv UNUSED)
...
@@ -65,7 +65,7 @@ main(int argc UNUSED, char **argv UNUSED)
for
(;;)
for
(;;)
{
{
int
nbytes
;
/* Number of bytes read frmo disk at each iteration */
int
nbytes
;
/* Number of bytes read frmo disk at each iteration */
unsigned
decoded_bytes
;
/* Bytes actually generated at each iteration */
size_t
decoded_bytes
;
/* Bytes actually generated at each iteration */
nbytes
=
fread
(
buffer
,
1
,
CHUNK_SIZE
,
stdin
);
nbytes
=
fread
(
buffer
,
1
,
CHUNK_SIZE
,
stdin
);
...
@@ -75,30 +75,30 @@ main(int argc UNUSED, char **argv UNUSED)
...
@@ -75,30 +75,30 @@ main(int argc UNUSED, char **argv UNUSED)
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
decoded_bytes
=
BASE16_DECODE_LENGTH
(
nbytes
);
decoded_bytes
=
BASE16_DECODE_LENGTH
(
nbytes
);
/* Decodes one chunk: */
/* Decodes one chunk: */
if
(
!
base16_decode_update
(
&
b16_ctx
,
&
decoded_bytes
,
result
,
nbytes
,
buffer
))
if
(
!
base16_decode_update
(
&
b16_ctx
,
&
decoded_bytes
,
result
,
nbytes
,
buffer
))
{
{
werror
(
"Error decoding input (not base16?)
\n
"
);
werror
(
"Error decoding input (not base16?)
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
if
(
!
write_string
(
stdout
,
decoded_bytes
,
result
))
if
(
!
write_string
(
stdout
,
decoded_bytes
,
result
))
{
{
werror
(
"Error writing file: %s
\n
"
,
strerror
(
errno
));
werror
(
"Error writing file: %s
\n
"
,
strerror
(
errno
));
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
if
(
nbytes
<
CHUNK_SIZE
)
if
(
nbytes
<
CHUNK_SIZE
)
{
{
/* Check if decoding finalized OK: */
/* Check if decoding finalized OK: */
if
(
!
base16_decode_final
(
&
b16_ctx
))
if
(
!
base16_decode_final
(
&
b16_ctx
))
{
{
werror
(
"Decoding did not finish properly.
\n
"
);
werror
(
"Decoding did not finish properly.
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
break
;
break
;
}
}
}
}
if
(
fflush
(
stdout
)
!=
0
)
if
(
fflush
(
stdout
)
!=
0
)
...
...
examples/base64dec.c
View file @
86fdb2ce
...
@@ -65,7 +65,7 @@ main(int argc UNUSED, char **argv UNUSED)
...
@@ -65,7 +65,7 @@ main(int argc UNUSED, char **argv UNUSED)
for
(;;)
for
(;;)
{
{
int
nbytes
;
/* Number of bytes read frmo disk at each iteration */
int
nbytes
;
/* Number of bytes read frmo disk at each iteration */
unsigned
decoded_bytes
;
/* Bytes actually generated at each iteration */
size_t
decoded_bytes
;
/* Bytes actually generated at each iteration */
nbytes
=
fread
(
buffer
,
1
,
CHUNK_SIZE
,
stdin
);
nbytes
=
fread
(
buffer
,
1
,
CHUNK_SIZE
,
stdin
);
...
...
nettle-types.h
View file @
86fdb2ce
...
@@ -67,20 +67,20 @@ typedef void nettle_hash_digest_func(void *ctx,
...
@@ -67,20 +67,20 @@ typedef void nettle_hash_digest_func(void *ctx,
/* ASCII armor codecs. NOTE: Experimental and subject to change. */
/* ASCII armor codecs. NOTE: Experimental and subject to change. */
typedef
unsigned
nettle_armor_length_func
(
unsigned
length
);
typedef
size_t
nettle_armor_length_func
(
size_t
length
);
typedef
void
nettle_armor_init_func
(
void
*
ctx
);
typedef
void
nettle_armor_init_func
(
void
*
ctx
);
typedef
unsigned
nettle_armor_encode_update_func
(
void
*
ctx
,
typedef
size_t
nettle_armor_encode_update_func
(
void
*
ctx
,
uint8_t
*
dst
,
uint8_t
*
dst
,
unsigned
src_length
,
size_t
src_length
,
const
uint8_t
*
src
);
const
uint8_t
*
src
);
typedef
unsigned
nettle_armor_encode_final_func
(
void
*
ctx
,
uint8_t
*
dst
);
typedef
size_t
nettle_armor_encode_final_func
(
void
*
ctx
,
uint8_t
*
dst
);
typedef
int
nettle_armor_decode_update_func
(
void
*
ctx
,
typedef
int
nettle_armor_decode_update_func
(
void
*
ctx
,
unsigned
*
dst_length
,
size_t
*
dst_length
,
uint8_t
*
dst
,
uint8_t
*
dst
,
unsigned
src_length
,
size_t
src_length
,
const
uint8_t
*
src
);
const
uint8_t
*
src
);
typedef
int
nettle_armor_decode_final_func
(
void
*
ctx
);
typedef
int
nettle_armor_decode_final_func
(
void
*
ctx
);
...
...
sexp-format.c
View file @
86fdb2ce
...
@@ -40,14 +40,14 @@
...
@@ -40,14 +40,14 @@
static
unsigned
static
unsigned
format_prefix
(
struct
nettle_buffer
*
buffer
,
format_prefix
(
struct
nettle_buffer
*
buffer
,
unsigned
length
)
size_t
length
)
{
{
unsigned
digit
=
1
;
size_t
digit
=
1
;
unsigned
prefix_length
=
1
;
unsigned
prefix_length
=
1
;
for
(;;)
for
(;;)
{
{
unsigned
next
=
digit
*
10
;