mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:07:36 +00:00
LibWeb: Move code that generates uuid into separate function
Make possible to generate uuid without having crypto class instance.
This commit is contained in:
parent
12cd74495a
commit
e8550ed21d
2 changed files with 21 additions and 12 deletions
|
@ -72,6 +72,18 @@ WebIDL::ExceptionOr<String> Crypto::random_uuid() const
|
||||||
{
|
{
|
||||||
auto& vm = realm().vm();
|
auto& vm = realm().vm();
|
||||||
|
|
||||||
|
return TRY_OR_THROW_OOM(vm, generate_random_uuid());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Crypto::visit_edges(Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_subtle.ptr());
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/webcrypto/#dfn-generate-a-random-uuid
|
||||||
|
ErrorOr<String> generate_random_uuid()
|
||||||
|
{
|
||||||
// 1. Let bytes be a byte sequence of length 16.
|
// 1. Let bytes be a byte sequence of length 16.
|
||||||
u8 bytes[16];
|
u8 bytes[16];
|
||||||
|
|
||||||
|
@ -113,18 +125,13 @@ WebIDL::ExceptionOr<String> Crypto::random_uuid() const
|
||||||
».
|
».
|
||||||
*/
|
*/
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}{:02x}{:02x}-", bytes[0], bytes[1], bytes[2], bytes[3]));
|
TRY(builder.try_appendff("{:02x}{:02x}{:02x}{:02x}-", bytes[0], bytes[1], bytes[2], bytes[3]));
|
||||||
TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}-", bytes[4], bytes[5]));
|
TRY(builder.try_appendff("{:02x}{:02x}-", bytes[4], bytes[5]));
|
||||||
TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}-", bytes[6], bytes[7]));
|
TRY(builder.try_appendff("{:02x}{:02x}-", bytes[6], bytes[7]));
|
||||||
TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}-", bytes[8], bytes[9]));
|
TRY(builder.try_appendff("{:02x}{:02x}-", bytes[8], bytes[9]));
|
||||||
TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]));
|
TRY(builder.try_appendff("{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]));
|
||||||
return TRY_OR_THROW_OOM(vm, builder.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Crypto::visit_edges(Cell::Visitor& visitor)
|
return builder.to_string();
|
||||||
{
|
};
|
||||||
Base::visit_edges(visitor);
|
|
||||||
visitor.visit(m_subtle.ptr());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,4 +35,6 @@ private:
|
||||||
JS::GCPtr<SubtleCrypto> m_subtle;
|
JS::GCPtr<SubtleCrypto> m_subtle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ErrorOr<String> generate_random_uuid();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue