Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F630342
mc-fle2-tag-and-encrypted-metadata-block.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
mc-fle2-tag-and-encrypted-metadata-block.c
View Options
/*
* Copyright 2024-present MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include
"mc-fle2-tag-and-encrypted-metadata-block-private.h"
#include
"mc-reader-private.h"
#include
"mc-writer-private.h"
#include
"mongocrypt-private.h"
#define CHECK_AND_RETURN(x) \
if (!(x)) { \
return false; \
} else \
((void)0)
void
mc_FLE2TagAndEncryptedMetadataBlock_init
(
mc_FLE2TagAndEncryptedMetadataBlock_t
*
metadata
)
{
BSON_ASSERT_PARAM
(
metadata
);
memset
(
metadata
,
0
,
sizeof
(
mc_FLE2TagAndEncryptedMetadataBlock_t
));
}
void
mc_FLE2TagAndEncryptedMetadataBlock_cleanup
(
mc_FLE2TagAndEncryptedMetadataBlock_t
*
metadata
)
{
BSON_ASSERT_PARAM
(
metadata
);
_mongocrypt_buffer_cleanup
(
&
metadata
->
rawBlock
);
_mongocrypt_buffer_cleanup
(
&
metadata
->
encryptedCount
);
_mongocrypt_buffer_cleanup
(
&
metadata
->
tag
);
_mongocrypt_buffer_cleanup
(
&
metadata
->
encryptedZeros
);
}
bool
mc_FLE2TagAndEncryptedMetadataBlock_parse
(
mc_FLE2TagAndEncryptedMetadataBlock_t
*
metadata
,
const
_mongocrypt_buffer_t
*
buf
,
mongocrypt_status_t
*
status
)
{
BSON_ASSERT_PARAM
(
metadata
);
BSON_ASSERT_PARAM
(
buf
);
if
((
buf
->
data
==
NULL
)
||
(
buf
->
len
==
0
))
{
CLIENT_ERR
(
"Empty buffer passed to mc_FLE2IndexedEncryptedValueV2_parse"
);
return
false
;
}
mc_reader_t
reader
;
mc_reader_init_from_buffer
(
&
reader
,
buf
,
__func__
);
mc_FLE2TagAndEncryptedMetadataBlock_init
(
metadata
);
CHECK_AND_RETURN
(
mc_reader_read_buffer
(
&
reader
,
&
metadata
->
rawBlock
,
kMetadataLen
,
status
));
uint64_t
offset
=
0
;
_mongocrypt_buffer_from_data
(
&
metadata
->
encryptedCount
,
metadata
->
rawBlock
.
data
+
offset
,
kFieldLen
);
offset
+=
kFieldLen
;
_mongocrypt_buffer_from_data
(
&
metadata
->
tag
,
metadata
->
rawBlock
.
data
+
offset
,
kFieldLen
);
offset
+=
kFieldLen
;
_mongocrypt_buffer_from_data
(
&
metadata
->
encryptedZeros
,
metadata
->
rawBlock
.
data
+
offset
,
kFieldLen
);
return
true
;
}
bool
mc_FLE2TagAndEncryptedMetadataBlock_serialize
(
const
mc_FLE2TagAndEncryptedMetadataBlock_t
*
metadata
,
_mongocrypt_buffer_t
*
buf
,
mongocrypt_status_t
*
status
)
{
BSON_ASSERT_PARAM
(
metadata
);
BSON_ASSERT_PARAM
(
buf
);
_mongocrypt_buffer_resize
(
buf
,
kMetadataLen
);
mc_writer_t
writer
;
mc_writer_init_from_buffer
(
&
writer
,
buf
,
__func__
);
CHECK_AND_RETURN
(
mc_writer_write_buffer
(
&
writer
,
&
metadata
->
rawBlock
,
kMetadataLen
,
status
));
return
true
;
}
#define CHECK(condition, msg) \
do { \
if (!(condition)) { \
CLIENT_ERR("mc_FLE2TagAndEncryptedMetadataBlock_validate failed: " msg); \
return false; \
} \
} while (0)
bool
mc_FLE2TagAndEncryptedMetadataBlock_validate
(
const
mc_FLE2TagAndEncryptedMetadataBlock_t
*
metadata
,
mongocrypt_status_t
*
status
)
{
CHECK
(
metadata
->
rawBlock
.
len
==
kMetadataLen
,
"Length of metadata block was unexpected"
);
CHECK
(
metadata
->
encryptedCount
.
len
==
kFieldLen
,
"Length of encrypted count was unexpected"
);
CHECK
(
metadata
->
tag
.
len
==
kFieldLen
,
"Length of tag was unexpected"
);
CHECK
(
metadata
->
encryptedZeros
.
len
==
kFieldLen
,
"Length of encrypted zeros was unexpected"
);
return
true
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Nov 15, 9:15 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
138223
Default Alt Text
mc-fle2-tag-and-encrypted-metadata-block.c (4 KB)
Attached To
Mode
R114 php-mongodb
Attached
Detach File
Event Timeline