Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
understanding makefile
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
CAPACES Nicolas
understanding makefile
Commits
9a748595
Commit
9a748595
authored
1 year ago
by
CAPACES Nicolas
Browse files
Options
Downloads
Patches
Plain Diff
ajout librairie
parent
be0a4bda
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
base64.c
+72
-0
72 additions, 0 deletions
base64.c
base64.h
+31
-0
31 additions, 0 deletions
base64.h
with
103 additions
and
0 deletions
base64.c
0 → 100644
+
72
−
0
View file @
9a748595
/*****************************************
* Nom: base64.c *
* Auteur: Nicolas CAPACES *
* Date de Creation: 19/05/2024 *
* Date de Modification: 20/05/2024 *
*****************************************/
#include
<sys/types.h>
#include
<stdint.h>
#include
<stddef.h>
#include
<stdlib.h>
#include
<string.h>
#include
<base64.h>
#include
<stdio.h>
const
char
pad
=
'='
;
size_t
base64_encoded_size
(
size_t
binlen
){
size_t
ret
;
ret
=
binlen
;
if
(
binlen
%
3
!=
0
)
ret
+=
3
-
(
binlen
%
3
);
ret
/=
3
;
ret
*=
4
;
return
ret
;
}
int
bin_to_base64
(
const
char
*
src
,
size_t
len_src
,
char
*
dst
,
size_t
len_dst
,
enum64
charset
){
size_t
i
;
size_t
j
;
size_t
v
;
char
*
used_set
;
if
(
src
==
NULL
||
len_src
==
0
||
len_dst
==
0
)
return
-
1
;
if
(
charset
==
STANDARD
){
used_set
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
}
else
if
(
charset
==
URL
){
used_set
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
;
}
else
{
return
-
1
;
}
dst
=
malloc
(
len_dst
);
dst
[
len_dst
]
=
'\0'
;
for
(
i
=
0
,
j
=
0
;
i
<
len_src
;
i
+=
3
,
j
+=
4
)
{
v
=
src
[
i
];
v
=
i
+
1
<
len_src
?
v
<<
8
|
src
[
i
+
1
]
:
v
<<
8
;
v
=
i
+
2
<
len_src
?
v
<<
8
|
src
[
i
+
2
]
:
v
<<
8
;
dst
[
j
]
=
used_set
[(
v
>>
18
)
&
0x3F
];
dst
[
j
+
1
]
=
used_set
[(
v
>>
12
)
&
0x3F
];
if
(
i
+
1
<
len_src
)
{
dst
[
j
+
2
]
=
used_set
[(
v
>>
6
)
&
0x3F
];
}
else
{
dst
[
j
+
2
]
=
pad
;
}
if
(
i
+
2
<
len_src
)
{
dst
[
j
+
3
]
=
used_set
[
v
&
0x3F
];
}
else
{
dst
[
j
+
3
]
=
pad
;
}
}
return
0
;
}
This diff is collapsed.
Click to expand it.
base64.h
0 → 100644
+
31
−
0
View file @
9a748595
/*****************************************
* Nom: base64.h *
* Auteur: Nicolas CAPACES *
* Date de Creation: 19/05/2024 *
* Date de Modification: 20/05/2024 *
*****************************************/
#ifndef BASE_64_H_
#define BASE_64_H_
#include
<sys/types.h>
#include
<stdint.h>
extern
const
char
standb64
[];
extern
const
char
URLb64
[];
extern
const
char
pad
;
typedef
enum
{
STANDARD
,
URL
}
enum64
;
//TODO: implementer le décodage
extern
int
bin_to_base64
(
const
char
*
src
,
size_t
len_src
,
char
*
dst
,
size_t
len_dst
,
enum64
charset
);
//extern int base64_to_bin(const char* src, size_t len_src, char* dst, size_t len_dst, enum64 charset);
extern
size_t
base64_encoded_size
(
size_t
binlen
);
//extern size_t base64_decoded_size(size_t base64len);
#endif
/*base64.h*/
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