Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
fea12d07
Commit
fea12d07
authored
Jul 10, 2023
by
Samir Halilcevic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try partial integration
parent
aaa1a8f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
0 deletions
+93
-0
libcaf_core/caf/detail/rfc3629.hpp
libcaf_core/caf/detail/rfc3629.hpp
+30
-0
libcaf_core/test/detail/rfc3629.cpp
libcaf_core/test/detail/rfc3629.cpp
+63
-0
No files found.
libcaf_core/caf/detail/rfc3629.hpp
View file @
fea12d07
...
...
@@ -15,6 +15,36 @@ namespace caf::detail {
/// https://datatracker.ietf.org/doc/html/rfc3629 for details.
class
CAF_CORE_EXPORT
rfc3629
{
public:
enum
class
validation_result
{
valid
=
0
,
incomplete_data
,
invalid_code_point
,
malformed_message
,
};
// 1. suggestion
/// Checks whether the begining of `bytes` is a valid UTF-8 string and returns
/// the end of the validated segment.
/// In case of validation_result::valid, the index is equal to bytes.size()
/// Otherwise, index points to the end of the valid utf-8 range between [0,
/// size) and the validation_result indicates the reason of failure.
static
std
::
pair
<
const_byte_span
::
index_type
,
validation_result
>
validate_prefix
(
const_byte_span
bytes
)
noexcept
;
/// Returns -1 on hard failure, index otherwise
static
const_byte_span
::
index_type
validate_prefix
(
const_byte_span
bytes
)
noexcept
;
/// Returns validation result and sets begin to end of the valid utf-8 range
static
validation_result
validate_prefix
(
const_byte_span
::
iterator
&
begin
,
const_byte_span
::
iterator
end
)
noexcept
;
/// Checks whether `str` is a valid UTF-8 string.
static
std
::
optional
<
std
::
string_view
::
size_type
>
validate_prefix
(
std
::
string_view
str
)
noexcept
;
/// Checks whether `bytes` is a valid UTF-8 string.
static
bool
valid
(
const_byte_span
bytes
)
noexcept
;
...
...
libcaf_core/test/detail/rfc3629.cpp
View file @
fea12d07
...
...
@@ -162,3 +162,66 @@ TEST_CASE("invalid UTF-8 input") {
CHECK
(
!
valid_utf8
(
invalid_four_byte_9
));
CHECK
(
!
valid_utf8
(
invalid_four_byte_10
));
}
namespace
{
std
::
byte
hex_to_byte
(
char
c
)
{
if
(
std
::
isdigit
(
c
))
return
static_cast
<
std
::
byte
>
(
c
-
'0'
);
if
(
c
>=
'a'
&&
c
<=
'f'
)
return
static_cast
<
std
::
byte
>
(
c
-
'a'
+
10
);
return
static_cast
<
std
::
byte
>
(
c
-
'A'
+
10
);
}
byte_buffer
hex_to_bytes
(
std
::
string_view
hex
)
{
byte_buffer
result
;
for
(
auto
it
=
hex
.
begin
();
it
!=
hex
.
end
();
it
+=
2
)
result
.
push_back
(
hex_to_byte
(
*
it
)
<<
4
|
hex_to_byte
(
*
(
it
+
1
)));
return
result
;
}
std
::
string_view
to_msg
(
const
byte_buffer
&
bs
)
{
return
{
reinterpret_cast
<
const
char
*>
(
bs
.
data
()),
bs
.
size
()};
}
}
// namespace
using
namespace
std
::
literals
;
TEST_CASE
(
"invalid UTF-8 sequence"
)
{
{
byte_buffer
bs
{
0xce
_b
,
0xba
_b
,
0xe1
_b
,
0xbd
_b
,
0xb9
_b
,
0xcf
_b
,
0x83
_b
,
0xce
_b
,
0xbc
_b
,
0xce
_b
,
0xb5
_b
,
0xed
_b
,
0xa0
_b
,
0x80
_b
,
0x65
_b
,
0x64
_b
,
0x69
_b
,
0x74
_b
,
0x65
_b
,
0x64
_b
};
MESSAGE
(
"UTF-8 Payload: "
<<
to_msg
(
bs
));
CHECK
(
valid_utf8
(
bs
));
}
{
auto
bs
=
byte_buffer
{
0x48
_b
,
0x65
_b
,
0x6c
_b
,
0x6c
_b
,
0x6f
_b
,
0x2d
_b
,
0xc2
_b
,
0xb5
_b
,
0x40
_b
,
0xc3
_b
,
0x9f
_b
,
0xc3
_b
,
0xb6
_b
,
0xc3
_b
,
0xa4
_b
,
0xc3
_b
,
0xbc
_b
,
0xc3
_b
,
0xa0
_b
,
0xc3
_b
,
0xa1
_b
,
0x2d
_b
,
0x55
_b
,
0x54
_b
,
0x46
_b
,
0x2d
_b
,
0x38
_b
,
0x21
_b
,
0x21
_b
};
MESSAGE
(
"UTF-8 Payload: "
<<
to_msg
(
bs
));
CHECK
(
valid_utf8
(
bs
));
}
{
auto
bs
=
hex_to_bytes
(
"48656c6c6f2dc2b540c39fc3b6c3a4"
sv
);
MESSAGE
(
"UTF-8 Payload: "
<<
to_msg
(
bs
));
CHECK
(
valid_utf8
(
bs
));
bs
=
hex_to_bytes
(
"c3bcc3a0c3a12d5554462d382121"
sv
);
MESSAGE
(
"UTF-8 Payload: "
<<
to_msg
(
bs
));
CHECK
(
valid_utf8
(
bs
));
}
auto
b1
=
byte_buffer
({
0xce
_b
,
0xba
_b
,
0xe1
_b
,
0xbd
_b
,
0xb9
_b
,
0xcf
_b
,
0x83
_b
,
0xce
_b
,
0xbc
_b
,
0xce
_b
,
0xb5
_b
});
auto
b2
=
byte_buffer
({
0xf4
_b
,
0x90
_b
,
0x80
_b
,
0x80
_b
});
auto
b3
=
byte_buffer
({
0x65
_b
,
0x64
_b
,
0x69
_b
,
0x74
_b
,
0x65
_b
,
0x64
_b
});
CHECK
(
valid_utf8
(
b1
));
CHECK
(
valid_utf8
(
b2
));
CHECK
(
valid_utf8
(
b3
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment