5  * Copyright (c) 2015 Apple Inc. All Rights Reserved. 
   7  * @APPLE_LICENSE_HEADER_START@ 
   9  * This file contains Original Code and/or Modifications of Original Code 
  10  * as defined in and that are subject to the Apple Public Source License 
  11  * Version 2.0 (the 'License'). You may not use this file except in 
  12  * compliance with the License. Please obtain a copy of the License at 
  13  * http://www.opensource.apple.com/apsl/ and read it before using this 
  16  * The Original Code and all software distributed under the License are 
  17  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  18  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  19  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  20  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  21  * Please see the License for the specific language governing rights and 
  22  * limitations under the License. 
  24  * @APPLE_LICENSE_HEADER_END@ 
  27 #include <AssertMacros.h> 
  28 #include <utilities/SecCFWrappers.h> 
  29 #include "SecSCTUtils.h" 
  31 static size_t SSLDecodeSize(const uint8_t *p
) 
  33     return (p
[0]<<8 | p
[1]); 
  36 CFArrayRef 
SecCreateSignedCertificateTimestampsArrayFromSerializedSCTList(const uint8_t *p
, size_t listLen
) 
  38     size_t encodedListLen
; 
  39     CFMutableArrayRef sctArray 
= CFArrayCreateMutable(kCFAllocatorDefault
, 0, &kCFTypeArrayCallBacks
); 
  40     require_quiet(sctArray
, out
); 
  42     require(listLen 
> 2 , out
); 
  43     encodedListLen 
= SSLDecodeSize(p
); p
+=2; listLen
-=2; 
  45     require(encodedListLen
==listLen
, out
); 
  50         require(listLen 
>= 2, out
); 
  51         itemLen 
= SSLDecodeSize(p
); p 
+= 2; listLen
-=2; 
  52         require(itemLen 
<= listLen
, out
); 
  53         CFDataRef sctData 
= CFDataCreate(kCFAllocatorDefault
, p
, itemLen
); 
  54         p 
+= itemLen
; listLen 
-= itemLen
; 
  55         require(sctData
, out
); 
  56         CFArrayAppendValue(sctArray
, sctData
); 
  57         CFReleaseSafe(sctData
); 
  63     CFReleaseSafe(sctArray
);