@sswroom/sswr 1.5.4 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog +30 -0
- package/cert.d.ts +411 -0
- package/cert.js +4616 -0
- package/certutil.d.ts +376 -0
- package/certutil.js +2692 -0
- package/cesium.d.ts +13 -13
- package/cesium.js +8 -4
- package/data.d.ts +76 -30
- package/data.js +342 -75
- package/geometry.d.ts +2 -2
- package/hash.d.ts +57 -0
- package/hash.js +269 -0
- package/hkoapi.d.ts +26 -26
- package/kml.d.ts +53 -16
- package/kml.js +115 -2
- package/leaflet.d.ts +17 -7
- package/leaflet.js +55 -4
- package/map.d.ts +17 -16
- package/map.js +1 -1
- package/math.d.ts +13 -13
- package/media.d.ts +119 -0
- package/media.js +2272 -0
- package/net.d.ts +1 -0
- package/net.js +5 -0
- package/olayer2.d.ts +2 -2
- package/olayer2.js +8 -4
- package/package.json +1 -1
- package/parser.d.ts +8 -2
- package/parser.js +539 -3
- package/text.d.ts +3 -1
- package/text.js +70 -2
- package/unit.d.ts +2 -0
- package/unit.js +110 -0
- package/web.d.ts +3 -1
- package/web.js +54 -4
package/net.d.ts
CHANGED
package/net.js
CHANGED
|
@@ -74,3 +74,8 @@ export function oidToString(oid)
|
|
|
74
74
|
}
|
|
75
75
|
return ret.join(".");
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
export function getIPv4Name(ip)
|
|
79
|
+
{
|
|
80
|
+
return ((ip >> 24) & 0xff).toString() + "." + ((ip >> 16) & 0xff).toString() + "." + ((ip >> 8) & 0xff).toString() + "." + (ip & 0xff).toString()
|
|
81
|
+
}
|
package/olayer2.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare class Olayer2Options
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export function toPointArray(numArr: number[][], options: Olayer2Options): OpenLayers.Geometry.Point[];
|
|
14
|
-
export function
|
|
14
|
+
export function createFromKML(feature: kml.Feature | kml.KMLFile, options: Olayer2Options): Promise<OpenLayers.Feature.Vector | OpenLayers.Marker | any[] | null>;
|
|
15
15
|
export function createFromGeometry(geom: geometry, options: Olayer2Options): Promise<OpenLayers.Marker | OpenLayers.Geometry | null>;
|
|
16
16
|
|
|
17
17
|
export class Olayer2Map extends map.MapControl
|
|
@@ -33,7 +33,7 @@ export class Olayer2Map extends map.MapControl
|
|
|
33
33
|
createMarkerLayer(name: string, options?: LayerOptions): any;
|
|
34
34
|
createGeometryLayer(name: string, options?: LayerOptions): any;
|
|
35
35
|
addLayer(layer: any): void;
|
|
36
|
-
|
|
36
|
+
addKML(feature: kml.Feature | kml.KMLFile): void;
|
|
37
37
|
uninit(): void;
|
|
38
38
|
zoomIn(): void;
|
|
39
39
|
zoomOut(): void;
|
package/olayer2.js
CHANGED
|
@@ -19,8 +19,12 @@ export function toPointArray(numArr, options)
|
|
|
19
19
|
return ret;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export async function
|
|
22
|
+
export async function createFromKML(feature, options)
|
|
23
23
|
{
|
|
24
|
+
if (feature instanceof kml.KMLFile)
|
|
25
|
+
{
|
|
26
|
+
return await createFromKML(feature.root, options);
|
|
27
|
+
}
|
|
24
28
|
options = data.mergeOptions(options, {noPopup: false});
|
|
25
29
|
if (feature instanceof kml.Container)
|
|
26
30
|
{
|
|
@@ -29,7 +33,7 @@ export async function createFromKMLFeature(feature, options)
|
|
|
29
33
|
let layer;
|
|
30
34
|
for (i in feature.features)
|
|
31
35
|
{
|
|
32
|
-
layer = await
|
|
36
|
+
layer = await createFromKML(feature.features[i], options);
|
|
33
37
|
if (layer instanceof OpenLayers.Marker)
|
|
34
38
|
{
|
|
35
39
|
layers.push(layer);
|
|
@@ -348,9 +352,9 @@ export class Olayer2Map extends map.MapControl
|
|
|
348
352
|
}
|
|
349
353
|
}
|
|
350
354
|
|
|
351
|
-
|
|
355
|
+
addKML(feature)
|
|
352
356
|
{
|
|
353
|
-
|
|
357
|
+
createFromKML(feature, {map: this.map, objProjection: this.mapProjection, mapProjection: this.map.getProjectionObject()}).then((layer)=>{this.addLayer(layer);});
|
|
354
358
|
}
|
|
355
359
|
|
|
356
360
|
uninit()
|
package/package.json
CHANGED
package/parser.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import * as data from "./data";
|
|
1
2
|
import * as kml from "./kml";
|
|
2
3
|
|
|
3
|
-
export function parseXML(txt: string): kml.
|
|
4
|
-
|
|
4
|
+
export function parseXML(txt: string): kml.KMLFile | null;
|
|
5
|
+
/**
|
|
6
|
+
* Parse file into data.ParsedObject
|
|
7
|
+
* @param file file to be parsed
|
|
8
|
+
* @returns can be kml.KMLFile, media.StaticImage, cert.ASN1Data, null if failed
|
|
9
|
+
*/
|
|
10
|
+
export function parseFile(file: File | Response): Promise<data.ParsedObject | null>;
|
package/parser.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import * as cert from "./cert.js";
|
|
2
|
+
import { ASN1Util } from "./certutil.js";
|
|
3
|
+
import * as data from "./data.js";
|
|
1
4
|
import * as geometry from "./geometry.js";
|
|
2
5
|
import * as kml from "./kml.js";
|
|
6
|
+
import * as media from "./media.js";
|
|
3
7
|
import * as text from "./text.js";
|
|
4
8
|
import * as web from "./web.js";
|
|
5
9
|
|
|
@@ -275,6 +279,46 @@ function parseKMLContainer(container, kmlNode, doc)
|
|
|
275
279
|
case "visibility":
|
|
276
280
|
container.setVisibility(node.textContent == "1");
|
|
277
281
|
break;
|
|
282
|
+
case "atom:author":
|
|
283
|
+
for (subNode of node.childNodes)
|
|
284
|
+
{
|
|
285
|
+
switch (subNode.nodeName)
|
|
286
|
+
{
|
|
287
|
+
case "#text":
|
|
288
|
+
{
|
|
289
|
+
let txt = subNode.textContent.trim();
|
|
290
|
+
if (txt.length > 0)
|
|
291
|
+
{
|
|
292
|
+
if (container.author)
|
|
293
|
+
container.setAuthor(container.author + " " + txt);
|
|
294
|
+
else
|
|
295
|
+
container.setAuthor(txt);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
case "atom:name":
|
|
300
|
+
container.setAuthorName(subNode.textContent);
|
|
301
|
+
break;
|
|
302
|
+
default:
|
|
303
|
+
console.log("Unknown node in kml atom:author: "+subNode.nodeName, subNode);
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
308
|
+
case "atom:link":
|
|
309
|
+
for (subNode of node.attributes)
|
|
310
|
+
{
|
|
311
|
+
switch (subNode.name)
|
|
312
|
+
{
|
|
313
|
+
case "href":
|
|
314
|
+
container.setLink(subNode.value);
|
|
315
|
+
break;
|
|
316
|
+
default:
|
|
317
|
+
console.log("Unknown attribute in kml atom:link: "+subNode.nodeName, subNode);
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
break;
|
|
278
322
|
case "Style":
|
|
279
323
|
break;
|
|
280
324
|
case "StyleMap":
|
|
@@ -285,6 +329,11 @@ function parseKMLContainer(container, kmlNode, doc)
|
|
|
285
329
|
if (feature)
|
|
286
330
|
container.addFeature(feature);
|
|
287
331
|
break;
|
|
332
|
+
case "NetworkLink":
|
|
333
|
+
feature = parseKMLNetworkLink(node, doc || container);
|
|
334
|
+
if (feature)
|
|
335
|
+
container.addFeature(feature);
|
|
336
|
+
break;
|
|
288
337
|
case "LookAt":
|
|
289
338
|
container.setLookAt(parseKMLLookAt(node));
|
|
290
339
|
break;
|
|
@@ -574,6 +623,98 @@ function parseKMLGeometry(kmlNode)
|
|
|
574
623
|
return null;
|
|
575
624
|
}
|
|
576
625
|
|
|
626
|
+
function parseKMLNetworkLink(kmlNode, doc)
|
|
627
|
+
{
|
|
628
|
+
let name;
|
|
629
|
+
let description;
|
|
630
|
+
let open;
|
|
631
|
+
let refreshVisibility;
|
|
632
|
+
let flyToView;
|
|
633
|
+
let linkHref;
|
|
634
|
+
let refreshMode;
|
|
635
|
+
let refreshInterval;
|
|
636
|
+
let viewRefreshMode;
|
|
637
|
+
|
|
638
|
+
let feature;
|
|
639
|
+
let node;
|
|
640
|
+
let subNode;
|
|
641
|
+
for (node of kmlNode.childNodes)
|
|
642
|
+
{
|
|
643
|
+
switch (node.nodeName)
|
|
644
|
+
{
|
|
645
|
+
case "#text":
|
|
646
|
+
break;
|
|
647
|
+
case "name":
|
|
648
|
+
name = node.textContent;
|
|
649
|
+
break;
|
|
650
|
+
case "description":
|
|
651
|
+
description = node.textContent.trim();
|
|
652
|
+
break;
|
|
653
|
+
case "open":
|
|
654
|
+
open = (node.textContent == "1");
|
|
655
|
+
break;
|
|
656
|
+
case "refreshVisibility":
|
|
657
|
+
refreshVisibility = (node.textContent == "1");
|
|
658
|
+
break;
|
|
659
|
+
case "flyToView":
|
|
660
|
+
flyToView = (node.textContent == "1");
|
|
661
|
+
break;
|
|
662
|
+
case "Link":
|
|
663
|
+
for (subNode of node.childNodes)
|
|
664
|
+
{
|
|
665
|
+
switch (subNode.nodeName)
|
|
666
|
+
{
|
|
667
|
+
case "#comment":
|
|
668
|
+
break;
|
|
669
|
+
case "#text":
|
|
670
|
+
break;
|
|
671
|
+
case "href":
|
|
672
|
+
linkHref = subNode.textContent;
|
|
673
|
+
break;
|
|
674
|
+
case "refreshMode":
|
|
675
|
+
refreshMode = subNode.textContent;
|
|
676
|
+
break;
|
|
677
|
+
case "refreshInterval":
|
|
678
|
+
refreshInterval = subNode.textContent;
|
|
679
|
+
break;
|
|
680
|
+
case "viewRefreshMode":
|
|
681
|
+
viewRefreshMode = subNode.textContent;
|
|
682
|
+
break;
|
|
683
|
+
default:
|
|
684
|
+
console.log("Unknown node in kml NetworkLink.Link", subNode);
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
break;
|
|
689
|
+
default:
|
|
690
|
+
console.log("Unknown node in kml NetworkLink", node);
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (linkHref)
|
|
695
|
+
{
|
|
696
|
+
feature = new kml.NetworkLink(linkHref);
|
|
697
|
+
if (name)
|
|
698
|
+
feature.setName(name);
|
|
699
|
+
if (description)
|
|
700
|
+
feature.setDescription(description);
|
|
701
|
+
if (open != null)
|
|
702
|
+
feature.setOpen(open);
|
|
703
|
+
if (refreshVisibility != null)
|
|
704
|
+
feature.setRefreshVisibility(refreshVisibility);
|
|
705
|
+
if (flyToView != null)
|
|
706
|
+
feature.setFlyToView(flyToView);
|
|
707
|
+
if (refreshMode)
|
|
708
|
+
feature.setRefreshMode(refreshMode);
|
|
709
|
+
if (refreshInterval)
|
|
710
|
+
feature.setRefreshInterval(Number.parseFloat(refreshInterval));
|
|
711
|
+
if (viewRefreshMode)
|
|
712
|
+
feature.setViewRefreshMode(viewRefreshMode);
|
|
713
|
+
return feature;
|
|
714
|
+
}
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
|
|
577
718
|
function parseKMLLookAt(kmlNode)
|
|
578
719
|
{
|
|
579
720
|
let longitude;
|
|
@@ -654,7 +795,387 @@ function parseKMLNode(kmlNode, doc)
|
|
|
654
795
|
}
|
|
655
796
|
}
|
|
656
797
|
|
|
657
|
-
|
|
798
|
+
async function parseJpg(reader)
|
|
799
|
+
{
|
|
800
|
+
if (!(reader instanceof data.ByteReader))
|
|
801
|
+
return null;
|
|
802
|
+
if (reader.getLength() < 2)
|
|
803
|
+
return null;
|
|
804
|
+
if (reader.readUInt8(0) != 0xff || reader.readUInt8(1) != 0xd8)
|
|
805
|
+
return null;
|
|
806
|
+
let ofst = 2;
|
|
807
|
+
let ret = false;
|
|
808
|
+
let j;
|
|
809
|
+
let exif;
|
|
810
|
+
while (true)
|
|
811
|
+
{
|
|
812
|
+
if (ofst + 4 > reader.getLength())
|
|
813
|
+
{
|
|
814
|
+
ret = false;
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
if (reader.readUInt8(ofst + 0) != 0xff)
|
|
818
|
+
{
|
|
819
|
+
ret = false;
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
822
|
+
if (reader.readUInt8(ofst + 1) == 0xdb)
|
|
823
|
+
{
|
|
824
|
+
ret = true;
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
j = ((reader.readUInt8(ofst + 2) << 8) | reader.readUInt8(ofst + 3)) - 2;
|
|
829
|
+
if (reader.readUInt8(ofst + 1) == 0xe1)
|
|
830
|
+
{
|
|
831
|
+
let t = reader.readUTF8Z(ofst + 4, 14);
|
|
832
|
+
if (t == "Exif")
|
|
833
|
+
{
|
|
834
|
+
let lsb;
|
|
835
|
+
if (reader.readUTF8(ofst + 10, 2) == "II")
|
|
836
|
+
{
|
|
837
|
+
lsb = true;
|
|
838
|
+
}
|
|
839
|
+
else if (reader.readUTF8(ofst + 10, 2) == "MM")
|
|
840
|
+
{
|
|
841
|
+
lsb = false;
|
|
842
|
+
}
|
|
843
|
+
else
|
|
844
|
+
{
|
|
845
|
+
console.log("JPG Exif unknown byte order", reader.readUTF8(ofst + 10, 2));
|
|
846
|
+
ret = false;
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
if (reader.readUInt16(ofst + 12, lsb) != 42)
|
|
850
|
+
{
|
|
851
|
+
console.log("JPG Exif not 42", reader.readUInt16(ofst + 12, lsb));
|
|
852
|
+
ret = false;
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
if (reader.readUInt32(ofst + 14, lsb) != 8)
|
|
856
|
+
{
|
|
857
|
+
console.log("JPG Exif not 8", reader.readUInt32(ofst + 14, lsb));
|
|
858
|
+
ret = false;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
exif = media.EXIFData.parseIFD(reader, ofst + 18, lsb, null, ofst + 10);
|
|
862
|
+
if (exif == null)
|
|
863
|
+
{
|
|
864
|
+
console.log("Error in parsing EXIF");
|
|
865
|
+
}
|
|
866
|
+
ofst += j + 4;
|
|
867
|
+
}
|
|
868
|
+
else if (t == "FLIR")
|
|
869
|
+
{
|
|
870
|
+
/* if (buff[4] == 0 && buff[5] == 1)
|
|
871
|
+
{
|
|
872
|
+
if (flirMstm == 0 && buff[6] == 0)
|
|
873
|
+
{
|
|
874
|
+
flirMaxSegm = buff[7];
|
|
875
|
+
NEW_CLASS(flirMstm, IO::MemoryStream());
|
|
876
|
+
flirCurrSegm = buff[6];
|
|
877
|
+
Data::ByteBuffer tagBuff(j);
|
|
878
|
+
fd->GetRealData(ofst + 4, j, tagBuff);
|
|
879
|
+
flirMstm->Write(&tagBuff[8], j - 8);
|
|
880
|
+
}
|
|
881
|
+
else if (flirMstm && buff[6] == (flirCurrSegm + 1))
|
|
882
|
+
{
|
|
883
|
+
flirCurrSegm = (UInt8)(flirCurrSegm + 1);
|
|
884
|
+
Data::ByteBuffer tagBuff(j);
|
|
885
|
+
fd->GetRealData(ofst + 4, j, tagBuff);
|
|
886
|
+
flirMstm->Write(&tagBuff[8], j - 8);
|
|
887
|
+
}
|
|
888
|
+
}*/
|
|
889
|
+
ofst += j + 4;
|
|
890
|
+
}
|
|
891
|
+
else
|
|
892
|
+
{
|
|
893
|
+
console.log("Unknown type for e1", t);
|
|
894
|
+
ofst += j + 4;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
else if (reader.readUInt8(ofst + 1) == 0xe2)
|
|
898
|
+
{
|
|
899
|
+
let t = reader.readUTF8Z(ofst + 4);
|
|
900
|
+
if (t == "ICC_PROFILE")
|
|
901
|
+
{
|
|
902
|
+
let iccBuff = reader.getArrayBuffer(ofst + 4 + 14, j - 14);
|
|
903
|
+
/*
|
|
904
|
+
NotNullPtr<Media::ICCProfile> icc;
|
|
905
|
+
if (Media::ICCProfile::Parse(tagBuff.SubArray(14, j - 14)).SetTo(icc))
|
|
906
|
+
{
|
|
907
|
+
icc->SetToColorProfile(img->info.color);
|
|
908
|
+
icc.Delete();
|
|
909
|
+
}*/
|
|
910
|
+
console.log("ICC Profile found");
|
|
911
|
+
}
|
|
912
|
+
else
|
|
913
|
+
{
|
|
914
|
+
console.log("Unknown type for e2", t);
|
|
915
|
+
}
|
|
916
|
+
ofst += j + 4;
|
|
917
|
+
}
|
|
918
|
+
else
|
|
919
|
+
{
|
|
920
|
+
ofst += j + 4;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
if (ret)
|
|
924
|
+
{
|
|
925
|
+
let buff = reader.getArrayBuffer();
|
|
926
|
+
let b = new Blob([buff], {type: "image/jpeg"});
|
|
927
|
+
let img = await media.loadImageFromBlob(b);
|
|
928
|
+
let simg = new media.StaticImage(img, sourceName, "image/jpeg");
|
|
929
|
+
if (exif)
|
|
930
|
+
simg.setExif(exif);
|
|
931
|
+
return simg;
|
|
932
|
+
}
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
async function parseWebp(reader)
|
|
937
|
+
{
|
|
938
|
+
if (!(reader instanceof data.ByteReader))
|
|
939
|
+
return null;
|
|
940
|
+
if (reader.getLength() < 20)
|
|
941
|
+
return null;
|
|
942
|
+
if (reader.readUInt32(0, true) != 0x46464952 || reader.readUInt32(8, true) != 0x50424557 || reader.readUInt32(4, true) + 8 != reader.getLength())
|
|
943
|
+
return null;
|
|
944
|
+
let buff = reader.getArrayBuffer();
|
|
945
|
+
let b = new Blob([buff], {type: "image/webp"});
|
|
946
|
+
let img = await media.loadImageFromBlob(b);
|
|
947
|
+
let simg = new media.StaticImage(img, sourceName, "image/webp");
|
|
948
|
+
return simg;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
function parseX509(reader, fileName, mime)
|
|
952
|
+
{
|
|
953
|
+
if (!(reader instanceof data.ByteReader))
|
|
954
|
+
return null;
|
|
955
|
+
let initTxt;
|
|
956
|
+
let initOfst = 0;
|
|
957
|
+
if (reader.readUInt8(0) == 0xef && reader.readUInt8(1) == 0xbb && reader.readUInt8(2) == 0xbf)
|
|
958
|
+
{
|
|
959
|
+
initOfst = 3;
|
|
960
|
+
}
|
|
961
|
+
initTxt = reader.readUTF8(initOfst, 5);
|
|
962
|
+
if (initTxt == "-----")
|
|
963
|
+
{
|
|
964
|
+
let files = [];
|
|
965
|
+
let lines = text.splitLines(reader.readUTF8(initOfst, reader.getLength() - initOfst));
|
|
966
|
+
let i = 0;
|
|
967
|
+
let j = lines.length;
|
|
968
|
+
while (i < j)
|
|
969
|
+
{
|
|
970
|
+
if (lines[i] == "-----BEGIN CERTIFICATE-----")
|
|
971
|
+
{
|
|
972
|
+
let b64 = [];
|
|
973
|
+
i++;
|
|
974
|
+
while (true)
|
|
975
|
+
{
|
|
976
|
+
if (i >= j)
|
|
977
|
+
return null;
|
|
978
|
+
if (lines[i] == "-----END CERTIFICATE-----")
|
|
979
|
+
{
|
|
980
|
+
break;
|
|
981
|
+
}
|
|
982
|
+
else
|
|
983
|
+
{
|
|
984
|
+
b64.push(lines[i]);
|
|
985
|
+
}
|
|
986
|
+
i++;
|
|
987
|
+
}
|
|
988
|
+
files.push(new cert.X509Cert(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
989
|
+
}
|
|
990
|
+
else if (lines[i] == "-----BEGIN RSA PRIVATE KEY-----")
|
|
991
|
+
{
|
|
992
|
+
let b64 = [];
|
|
993
|
+
let enc = false;
|
|
994
|
+
i++;
|
|
995
|
+
while (true)
|
|
996
|
+
{
|
|
997
|
+
if (i >= j)
|
|
998
|
+
return null;
|
|
999
|
+
if (lines[i] == "-----END RSA PRIVATE KEY-----")
|
|
1000
|
+
{
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
else if (lines[i].startsWith("Proc-Type:"))
|
|
1004
|
+
{
|
|
1005
|
+
enc = true;
|
|
1006
|
+
}
|
|
1007
|
+
else
|
|
1008
|
+
{
|
|
1009
|
+
b64.push(lines[i]);
|
|
1010
|
+
}
|
|
1011
|
+
i++;
|
|
1012
|
+
}
|
|
1013
|
+
files.push(new cert.X509Key(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer, cert.KeyType.RSA));
|
|
1014
|
+
}
|
|
1015
|
+
else if (lines[i] == "-----BEGIN DSA PRIVATE KEY-----")
|
|
1016
|
+
{
|
|
1017
|
+
let b64 = [];
|
|
1018
|
+
i++;
|
|
1019
|
+
while (true)
|
|
1020
|
+
{
|
|
1021
|
+
if (i >= j)
|
|
1022
|
+
return null;
|
|
1023
|
+
if (lines[i] == "-----END DSA PRIVATE KEY-----")
|
|
1024
|
+
{
|
|
1025
|
+
break;
|
|
1026
|
+
}
|
|
1027
|
+
else
|
|
1028
|
+
{
|
|
1029
|
+
b64.push(lines[i]);
|
|
1030
|
+
}
|
|
1031
|
+
i++;
|
|
1032
|
+
}
|
|
1033
|
+
files.push(new cert.X509Key(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer, cert.KeyType.DSA));
|
|
1034
|
+
}
|
|
1035
|
+
else if (lines[i] == "-----BEGIN EC PRIVATE KEY-----")
|
|
1036
|
+
{
|
|
1037
|
+
let b64 = [];
|
|
1038
|
+
i++;
|
|
1039
|
+
while (true)
|
|
1040
|
+
{
|
|
1041
|
+
if (i >= j)
|
|
1042
|
+
return null;
|
|
1043
|
+
if (lines[i] == "-----END EC PRIVATE KEY-----")
|
|
1044
|
+
{
|
|
1045
|
+
break;
|
|
1046
|
+
}
|
|
1047
|
+
else
|
|
1048
|
+
{
|
|
1049
|
+
b64.push(lines[i]);
|
|
1050
|
+
}
|
|
1051
|
+
i++;
|
|
1052
|
+
}
|
|
1053
|
+
files.push(new cert.X509Key(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer, cert.KeyType.ECDSA));
|
|
1054
|
+
}
|
|
1055
|
+
else if (lines[i] == "-----BEGIN PRIVATE KEY-----")
|
|
1056
|
+
{
|
|
1057
|
+
let b64 = [];
|
|
1058
|
+
i++;
|
|
1059
|
+
while (true)
|
|
1060
|
+
{
|
|
1061
|
+
if (i >= j)
|
|
1062
|
+
return null;
|
|
1063
|
+
if (lines[i] == "-----END PRIVATE KEY-----")
|
|
1064
|
+
{
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
else
|
|
1068
|
+
{
|
|
1069
|
+
b64.push(lines[i]);
|
|
1070
|
+
}
|
|
1071
|
+
i++;
|
|
1072
|
+
}
|
|
1073
|
+
files.push(new cert.X509PrivKey(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
1074
|
+
}
|
|
1075
|
+
else if (lines[i] == "-----BEGIN PUBLIC KEY-----")
|
|
1076
|
+
{
|
|
1077
|
+
let b64 = [];
|
|
1078
|
+
i++;
|
|
1079
|
+
while (true)
|
|
1080
|
+
{
|
|
1081
|
+
if (i >= j)
|
|
1082
|
+
return null;
|
|
1083
|
+
if (lines[i] == "-----END PUBLIC KEY-----")
|
|
1084
|
+
{
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
else
|
|
1088
|
+
{
|
|
1089
|
+
b64.push(lines[i]);
|
|
1090
|
+
}
|
|
1091
|
+
i++;
|
|
1092
|
+
}
|
|
1093
|
+
files.push(new cert.X509PubKey(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
1094
|
+
}
|
|
1095
|
+
else if (lines[i] == "-----BEGIN CERTIFICATE REQUEST-----")
|
|
1096
|
+
{
|
|
1097
|
+
let b64 = [];
|
|
1098
|
+
i++;
|
|
1099
|
+
while (true)
|
|
1100
|
+
{
|
|
1101
|
+
if (i >= j)
|
|
1102
|
+
return null;
|
|
1103
|
+
if (lines[i] == "-----END CERTIFICATE REQUEST-----")
|
|
1104
|
+
{
|
|
1105
|
+
break;
|
|
1106
|
+
}
|
|
1107
|
+
else
|
|
1108
|
+
{
|
|
1109
|
+
b64.push(lines[i]);
|
|
1110
|
+
}
|
|
1111
|
+
i++;
|
|
1112
|
+
}
|
|
1113
|
+
files.push(new cert.X509CertReq(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
1114
|
+
}
|
|
1115
|
+
else if (lines[i] == "-----BEGIN NEW CERTIFICATE REQUEST-----")
|
|
1116
|
+
{
|
|
1117
|
+
let b64 = [];
|
|
1118
|
+
i++;
|
|
1119
|
+
while (true)
|
|
1120
|
+
{
|
|
1121
|
+
if (i >= j)
|
|
1122
|
+
return null;
|
|
1123
|
+
if (lines[i] == "-----END NEW CERTIFICATE REQUEST-----")
|
|
1124
|
+
{
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
else
|
|
1128
|
+
{
|
|
1129
|
+
b64.push(lines[i]);
|
|
1130
|
+
}
|
|
1131
|
+
i++;
|
|
1132
|
+
}
|
|
1133
|
+
files.push(new cert.X509CertReq(fileName, new text.Base64Enc().decodeBin(b64.join("")).buffer));
|
|
1134
|
+
}
|
|
1135
|
+
i++;
|
|
1136
|
+
}
|
|
1137
|
+
if (files.length == 1)
|
|
1138
|
+
{
|
|
1139
|
+
return files[0];
|
|
1140
|
+
}
|
|
1141
|
+
else if (files.length > 1)
|
|
1142
|
+
{
|
|
1143
|
+
let fileList = new cert.X509FileList(fileName, files[0]);
|
|
1144
|
+
let i = 1;
|
|
1145
|
+
while (i < files.length)
|
|
1146
|
+
{
|
|
1147
|
+
fileList.addFile(files[i]);
|
|
1148
|
+
i++;
|
|
1149
|
+
}
|
|
1150
|
+
return fileList;
|
|
1151
|
+
}
|
|
1152
|
+
console.log("Unsupported file", fileName, mime);
|
|
1153
|
+
}
|
|
1154
|
+
else if (reader.readUInt8(0) == 0x30 && ASN1Util.pduIsValid(reader, 0, reader.getLength()))
|
|
1155
|
+
{
|
|
1156
|
+
fileName = fileName.toUpperCase();
|
|
1157
|
+
console.log(mime);
|
|
1158
|
+
if (mime == "application/x-pkcs12" || fileName.endsWith(".P12") || fileName.endsWith(".PFX"))
|
|
1159
|
+
{
|
|
1160
|
+
return new cert.X509PKCS12(fileName, reader.getArrayBuffer());
|
|
1161
|
+
}
|
|
1162
|
+
else if (mime == "application/x-x509-ca-cert" || mime == "application/x-x509-user-cert" || mime == "application/pkix-cert" || fileName.endsWith(".DER") || fileName.endsWith(".CER") || fileName.endsWith(".CRT"))
|
|
1163
|
+
{
|
|
1164
|
+
return new cert.X509Cert(fileName, reader.getArrayBuffer());
|
|
1165
|
+
}
|
|
1166
|
+
else if (mime == "application/x-pkcs7-certificates" || fileName.endsWith(".P7B") || fileName.endsWith(".P7S"))
|
|
1167
|
+
{
|
|
1168
|
+
return new cert.X509PKCS7(fileName, reader.getArrayBuffer());
|
|
1169
|
+
}
|
|
1170
|
+
else if (mime == "application/pkix-crl" || fileName.endsWith(".CRL"))
|
|
1171
|
+
{
|
|
1172
|
+
return new cert.X509CRL(fileName, reader.getArrayBuffer());
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return null;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
export function parseXML(txt, sourceName)
|
|
658
1179
|
{
|
|
659
1180
|
let parser = new DOMParser();
|
|
660
1181
|
let xmlDoc = parser.parseFromString(txt, "application/xml");
|
|
@@ -672,7 +1193,17 @@ export function parseXML(txt)
|
|
|
672
1193
|
for (kmlNode of xmlRoot.childNodes)
|
|
673
1194
|
{
|
|
674
1195
|
if (kmlNode.nodeName != "#text")
|
|
675
|
-
|
|
1196
|
+
{
|
|
1197
|
+
let feature = parseKMLNode(kmlNode);
|
|
1198
|
+
if (feature)
|
|
1199
|
+
{
|
|
1200
|
+
return new kml.KMLFile(feature, sourceName);
|
|
1201
|
+
}
|
|
1202
|
+
else
|
|
1203
|
+
{
|
|
1204
|
+
return null;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
676
1207
|
}
|
|
677
1208
|
}
|
|
678
1209
|
else
|
|
@@ -696,10 +1227,15 @@ export async function parseFile(file)
|
|
|
696
1227
|
|
|
697
1228
|
if (t == "application/vnd.google-earth.kml+xml")
|
|
698
1229
|
{
|
|
699
|
-
return parseXML(await file.text());
|
|
1230
|
+
return parseXML(await file.text(), file.name);
|
|
700
1231
|
}
|
|
701
1232
|
else
|
|
702
1233
|
{
|
|
1234
|
+
let view = new data.ByteReader(await file.arrayBuffer());
|
|
1235
|
+
let obj;
|
|
1236
|
+
if (obj = await parseJpg(view, file.name)) return obj;
|
|
1237
|
+
if (obj = await parseWebp(view, file.name)) return obj;
|
|
1238
|
+
if (obj = parseX509(view, file.name, t)) return obj;
|
|
703
1239
|
console.log("Unsupported file type", t);
|
|
704
1240
|
return null;
|
|
705
1241
|
}
|
package/text.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export enum LineBreakType
|
|
|
10
10
|
CR,
|
|
11
11
|
LF,
|
|
12
12
|
CRLF
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
14
|
|
|
15
15
|
export function zeroPad(val: string | number, ndigits: number): string;
|
|
16
16
|
export function isInteger(s: string): boolean;
|
|
@@ -23,6 +23,8 @@ export function arrayToNumbers(arr: string[]): number[];
|
|
|
23
23
|
export function toHex8(v: number): string;
|
|
24
24
|
export function toHex16(v: number): string;
|
|
25
25
|
export function toHex32(v: number): string;
|
|
26
|
+
export function u8Arr2Hex(buff: Uint8Array, byteSep: string, rowSep: string): string;
|
|
27
|
+
export function splitLines(txt: string): string[];
|
|
26
28
|
export function getEncList(): TextBinEnc[];
|
|
27
29
|
|
|
28
30
|
export class TextBinEnc
|