Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nettle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmitry Baryshkov
nettle
Commits
a35ccc95
Commit
a35ccc95
authored
22 years ago
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
(pgp_armor): Use new base64 conventions.
Rev: src/nettle/pgp-encode.c:1.2
parent
bb34f1ed
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pgp-encode.c
+23
-8
23 additions, 8 deletions
pgp-encode.c
with
23 additions
and
8 deletions
pgp-encode.c
+
23
−
8
View file @
a35ccc95
...
...
@@ -329,10 +329,9 @@ pgp_crc24(unsigned length, const uint8_t *data)
#define WRITE(buffer, s) (nettle_buffer_write(buffer, strlen((s)), (s)))
/* Base 64 groups data per line */
#define GROUPS_PER_LINE 15
#define BINARY_PER_LINE (GROUPS_PER_LINE * BASE64_BINARY_BLOCK_SIZE)
#define TEXT_PER_LINE (GROUPS_PER_LINE * BASE64_BINARY_BLOCK_SIZE)
/* 15 base 64 groups data per line */
#define BINARY_PER_LINE 45
#define TEXT_PER_LINE BASE64_ENCODE_LENGTH(BINARY_PER_LINE)
int
pgp_armor
(
struct
nettle_buffer
*
buffer
,
...
...
@@ -340,7 +339,11 @@ pgp_armor(struct nettle_buffer *buffer,
unsigned
length
,
const
uint8_t
*
data
)
{
struct
base64_encode_ctx
ctx
;
unsigned
crc
=
pgp_crc24
(
length
,
data
);
base64_encode_init
(
&
ctx
);
if
(
!
(
WRITE
(
buffer
,
"BEGIN PGP "
)
&&
WRITE
(
buffer
,
tag
)
...
...
@@ -351,28 +354,40 @@ pgp_armor(struct nettle_buffer *buffer,
length
>=
BINARY_PER_LINE
;
length
-=
BINARY_PER_LINE
,
data
+=
BINARY_PER_LINE
)
{
unsigned
done
;
uint8_t
*
p
=
nettle_buffer_space
(
buffer
,
TEXT_PER_LINE
);
if
(
!
p
)
return
0
;
base64_encode
(
p
,
BINARY_PER_LINE
,
data
);
done
=
base64_encode_update
(
&
ctx
,
p
,
BINARY_PER_LINE
,
data
);
assert
(
done
<=
TEXT_PER_LINE
);
/* FIXME: Create some official way to do this */
buffer
->
size
-=
(
TEXT_PER_LINE
-
done
);
if
(
!
NETTLE_BUFFER_PUTC
(
buffer
,
'\n'
))
return
0
;
}
if
(
length
)
{
unsigned
text_size
=
BASE64_ENCODE_LENGTH
(
length
);
unsigned
text_size
=
BASE64_ENCODE_LENGTH
(
length
)
+
BASE64_ENCODE_FINAL_LENGTH
;
unsigned
done
;
uint8_t
*
p
=
nettle_buffer_space
(
buffer
,
text_size
);
if
(
!
p
)
return
0
;
base64_encode
(
p
,
length
,
data
);
done
=
base64_encode_update
(
&
ctx
,
p
,
length
,
data
);
done
+=
base64_encode_final
(
&
ctx
,
p
+
done
);
/* FIXME: Create some official way to do this */
buffer
->
size
-=
(
text_size
-
done
);
if
(
!
NETTLE_BUFFER_PUTC
(
buffer
,
'\n'
))
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment