shifro 1.2.1 → 1.2.2
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/README.md +2 -2
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +21 -13
- package/dist/index.mjs +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,11 +67,11 @@ import {
|
|
|
67
67
|
Input,
|
|
68
68
|
Output,
|
|
69
69
|
decryptBytes,
|
|
70
|
-
type
|
|
70
|
+
type EncryptedPacket,
|
|
71
71
|
} from 'shifro';
|
|
72
72
|
|
|
73
73
|
// Decrypt bytes with your DRM library
|
|
74
|
-
async function decryptProtectedData({ scheme, data, iv }:
|
|
74
|
+
async function decryptProtectedData({ scheme, data, iv }: EncryptedPacket) {
|
|
75
75
|
// Your decryption logic here
|
|
76
76
|
}
|
|
77
77
|
|
package/dist/cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { parseArgs } from "node:util";
|
|
|
3
3
|
import { ALL_FORMATS, Conversion, EncodedPacket, FilePathSource, FilePathTarget, Input, Mp4OutputFormat, Output } from "mediabunny";
|
|
4
4
|
//#region package.json
|
|
5
5
|
var name = "shifro";
|
|
6
|
-
var version = "1.2.
|
|
6
|
+
var version = "1.2.2";
|
|
7
7
|
var author = "Vitaly Gashkov <vitalygashkov@vk.com>";
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/mediabunny-isobmff.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -13,6 +13,15 @@ type EncryptionPattern = {
|
|
|
13
13
|
/** Number of consecutive 16-byte blocks that are encrypted in each pattern step. */cryptByteBlock: number; /** Number of consecutive 16-byte blocks that are skipped in each pattern step. */
|
|
14
14
|
skipByteBlock: number;
|
|
15
15
|
};
|
|
16
|
+
type EncryptionInfo = {
|
|
17
|
+
/** Key ID from the track encryption metadata. */keyId: string; /** PSSH boxes associated with this key/sample and useful for DRM-specific key resolution. */
|
|
18
|
+
psshBoxes: PsshBox[]; /** Sample encryption scheme. */
|
|
19
|
+
scheme: EncryptionScheme; /** Per-sample IV resolved from container metadata. */
|
|
20
|
+
iv: Uint8Array; /** Presentation timestamp of the sample in microseconds. */
|
|
21
|
+
timestamp: number; /** Subsample layout describing which parts of `data` are clear vs protected, or `null` for whole-sample encryption. */
|
|
22
|
+
subsamples: SubsampleEncryption[] | null; /** Pattern encryption parameters, or `null` when no pattern is used. */
|
|
23
|
+
pattern: EncryptionPattern | null;
|
|
24
|
+
};
|
|
16
25
|
/**
|
|
17
26
|
* Options passed to {@link DecryptSample}.
|
|
18
27
|
*
|
|
@@ -23,18 +32,17 @@ type EncryptionPattern = {
|
|
|
23
32
|
* that cannot be safely represented as a single flattened protected-byte stream, such as patterned `cbcs`
|
|
24
33
|
* subsample encryption.
|
|
25
34
|
*/
|
|
26
|
-
type EncryptedSample = {
|
|
27
|
-
/** Full sample bytes as stored in the container. Clear and protected regions are both present in this buffer. */data: Uint8Array;
|
|
28
|
-
keyId: string; /** PSSH boxes associated with this key/sample and useful for DRM-specific key resolution. */
|
|
29
|
-
psshBoxes: PsshBox[]; /** Sample encryption scheme. */
|
|
30
|
-
scheme: EncryptionScheme; /** Per-sample IV resolved from container metadata. */
|
|
31
|
-
iv: Uint8Array; /** Presentation timestamp of the sample in microseconds. */
|
|
32
|
-
timestamp: number; /** Subsample layout describing which parts of `data` are clear vs protected, or `null` for whole-sample encryption. */
|
|
33
|
-
subsamples: SubsampleEncryption[] | null; /** Pattern encryption parameters, or `null` when no pattern is used. */
|
|
34
|
-
pattern: EncryptionPattern | null;
|
|
35
|
+
type EncryptedSample = EncryptionInfo & {
|
|
36
|
+
/** Full sample bytes as stored in the container. Clear and protected regions are both present in this buffer. */data: Uint8Array;
|
|
35
37
|
};
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Options passed to {@link decryptBytes}.
|
|
40
|
+
*
|
|
41
|
+
* `data` contains only the bytes that still need decryption. When the helper has flattened clear or skipped regions
|
|
42
|
+
* out of the original sample, `subsamples` and `pattern` are normalized to describe this callback buffer instead of
|
|
43
|
+
* the original sample layout.
|
|
44
|
+
*/
|
|
45
|
+
type EncryptedPacket = EncryptionInfo & {
|
|
38
46
|
/** Only the encrypted bytes that should be decrypted. Clear sample bytes are not included. */data: Uint8Array;
|
|
39
47
|
};
|
|
40
48
|
/**
|
|
@@ -46,7 +54,7 @@ type EncryptedBytes = Omit<EncryptedSample, 'data'> & {
|
|
|
46
54
|
*/
|
|
47
55
|
type DecryptSample = (options: EncryptedSample) => MaybePromise<Uint8Array>;
|
|
48
56
|
/** Raw byte decryption callback used by {@link decryptBytes}. */
|
|
49
|
-
type DecryptBytesCallback = (options:
|
|
57
|
+
type DecryptBytesCallback = (options: EncryptedPacket) => MaybePromise<Uint8Array>;
|
|
50
58
|
declare const decryptBytes: (decryptBytesCallback: DecryptBytesCallback) => DecryptSample;
|
|
51
59
|
//#endregion
|
|
52
60
|
//#region src/index.d.ts
|
|
@@ -101,4 +109,4 @@ declare class Output extends Output$1 {
|
|
|
101
109
|
});
|
|
102
110
|
}
|
|
103
111
|
//#endregion
|
|
104
|
-
export { type DecryptBytesCallback, type DecryptSample, Conversion as Decryption, type
|
|
112
|
+
export { type DecryptBytesCallback, type DecryptSample, Conversion as Decryption, type EncryptedPacket, type EncryptedSample, type EncryptionPattern, FilePathSource, FilePathTarget, Input, type MediabunnyInputOptions as InputOptions, type Key, type KeyId, type KeyMap, MkvOutputFormat, MovOutputFormat, Mp3OutputFormat, Mp4OutputFormat, Output, type OutputFormat, type OutputOptions, ReadableStreamSource, ShifroInputOptions, StreamSource, type StreamSourceOptions, StreamTarget, type StreamTargetOptions, type SubsampleEncryption, UrlSource, decryptBytes };
|
package/dist/index.mjs
CHANGED
|
@@ -2,18 +2,18 @@ import { ALL_FORMATS, Conversion, EncodedPacket, FilePathSource, FilePathTarget,
|
|
|
2
2
|
//#region src/decrypt-sample.ts
|
|
3
3
|
const AES_BLOCK_SIZE = 16;
|
|
4
4
|
const isUint8Array$1 = (value) => value instanceof Uint8Array;
|
|
5
|
-
const
|
|
5
|
+
const normalizeSubsamples = (subsamples, protectedLength) => {
|
|
6
6
|
if (!subsamples) return null;
|
|
7
|
-
return
|
|
8
|
-
clearLen:
|
|
9
|
-
protectedLen:
|
|
10
|
-
}
|
|
7
|
+
return [{
|
|
8
|
+
clearLen: 0,
|
|
9
|
+
protectedLen: protectedLength
|
|
10
|
+
}];
|
|
11
11
|
};
|
|
12
|
-
const
|
|
13
|
-
if (!pattern) return null;
|
|
12
|
+
const normalizePattern = (scheme, pattern) => {
|
|
13
|
+
if (!pattern || scheme !== "cbcs") return null;
|
|
14
14
|
return {
|
|
15
|
-
cryptByteBlock:
|
|
16
|
-
skipByteBlock:
|
|
15
|
+
cryptByteBlock: 1,
|
|
16
|
+
skipByteBlock: 0
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
const collectProtectedRanges = (offset, protectedLen, pattern, fullBlocksOnly) => {
|
|
@@ -109,8 +109,8 @@ const decryptGroups = async (options, groups, decryptBytesCallback) => {
|
|
|
109
109
|
scheme: options.scheme,
|
|
110
110
|
iv: group.iv.slice(),
|
|
111
111
|
timestamp: options.timestamp,
|
|
112
|
-
subsamples:
|
|
113
|
-
pattern:
|
|
112
|
+
subsamples: normalizeSubsamples(options.subsamples, encryptedData.byteLength),
|
|
113
|
+
pattern: normalizePattern(options.scheme, options.pattern)
|
|
114
114
|
});
|
|
115
115
|
if (!isUint8Array$1(decryptedData)) throw new TypeError("decryptBytes callback must return a Uint8Array.");
|
|
116
116
|
if (decryptedData.byteLength !== encryptedData.byteLength) throw new Error("decryptBytes callback must return the same number of bytes as the encrypted input.");
|