5 // Created by Mitch Adler on 7/2/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_array(CFAllocatorRef allocator
, CFOptionFlags mutability
,
20 CFArrayRef
* array
, CFErrorRef
*error
,
21 const uint8_t* der
, const uint8_t *der_end
)
26 CFMutableArrayRef result
= CFArrayCreateMutable(allocator
, 0, &kCFTypeArrayCallBacks
);
28 const uint8_t *elements_end
;
29 const uint8_t *current_element
= ccder_decode_sequence_tl(&elements_end
, der
, der_end
);
31 while (current_element
!= NULL
&& current_element
< elements_end
) {
32 CFPropertyListRef element
= NULL
;
33 current_element
= der_decode_plist(allocator
, mutability
, &element
, error
, current_element
, elements_end
);
34 if (current_element
) {
35 CFArrayAppendValue(result
, element
);
36 CFReleaseNull(element
);
40 if (current_element
) {
45 CFReleaseNull(result
);
46 return current_element
;
50 size_t der_sizeof_array(CFArrayRef data
, CFErrorRef
*error
)
53 for(CFIndex position
= CFArrayGetCount(data
) - 1;
57 body_size
+= der_sizeof_plist(CFArrayGetValueAtIndex(data
, position
), error
);
59 return ccder_sizeof(CCDER_CONSTRUCTED_SEQUENCE
, body_size
);
63 uint8_t* der_encode_array(CFArrayRef array
, CFErrorRef
*error
,
64 const uint8_t *der
, uint8_t *der_end
)
66 uint8_t* original_der_end
= der_end
;
67 for(CFIndex position
= CFArrayGetCount(array
) - 1;
71 der_end
= der_encode_plist(CFArrayGetValueAtIndex(array
, position
), error
, der
, der_end
);
74 return ccder_encode_constructed_tl(CCDER_CONSTRUCTED_SEQUENCE
, original_der_end
, der
, der_end
);