5 // Created by Mitch Adler on 6/19/12.
6 // Copyright (c) 2012 Apple Inc. All rights reserved.
11 #include "utilities/SecCFRelease.h"
12 #include "utilities/der_plist.h"
13 #include "utilities/der_plist_internal.h"
15 #include <corecrypto/ccder.h>
16 #include <CoreFoundation/CoreFoundation.h>
19 const uint8_t* der_decode_boolean(CFAllocatorRef allocator
, CFOptionFlags mutability
,
20 CFBooleanRef
* boolean
, CFErrorRef
*error
,
21 const uint8_t* der
, const uint8_t *der_end
)
26 size_t payload_size
= 0;
27 const uint8_t *payload
= ccder_decode_tl(CCDER_BOOLEAN
, &payload_size
, der
, der_end
);
29 if (NULL
== payload
|| (der_end
- payload
) < payload_size
|| payload_size
!= 1) {
30 SecCFDERCreateError(kSecDERErrorUnknownEncoding
, CFSTR("Unknown boolean encoding"), NULL
, error
);
34 *boolean
= *payload
? kCFBooleanTrue
: kCFBooleanFalse
;
36 return payload
+ payload_size
;
40 size_t der_sizeof_boolean(CFBooleanRef data __unused
, CFErrorRef
*error
)
42 return ccder_sizeof(CCDER_BOOLEAN
, 1);
46 uint8_t* der_encode_boolean(CFBooleanRef boolean
, CFErrorRef
*error
,
47 const uint8_t *der
, uint8_t *der_end
)
49 uint8_t value
= CFBooleanGetValue(boolean
);
51 return ccder_encode_tl(CCDER_BOOLEAN
, 1, der
,
52 ccder_encode_body(1, &value
, der
, der_end
));