@ciphore/radiocli 0.2.4 → 0.2.5

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.
Files changed (134) hide show
  1. package/CHANGELOG.md +70 -2
  2. package/CONTRIBUTING.md +10 -0
  3. package/README.md +108 -253
  4. package/SECURITY.md +23 -1
  5. package/dist/agent/alarm-service.js +10 -7
  6. package/dist/agent/cli.js +16 -1
  7. package/dist/agent/command-schema.js +47 -0
  8. package/dist/agent/headless-host.js +226 -81
  9. package/dist/agent/launcher.js +2 -1
  10. package/dist/agent/mcp-server.js +10 -5
  11. package/dist/agent/service.js +75 -40
  12. package/dist/agent/session.js +214 -24
  13. package/dist/agent/tui-session.js +213 -0
  14. package/dist/alarms/cli.js +19 -3
  15. package/dist/alarms/occurrence-cache.js +25 -0
  16. package/dist/alarms/runner.js +87 -23
  17. package/dist/alarms/schedule.js +29 -1
  18. package/dist/alarms/scheduler.js +11 -3
  19. package/dist/alarms/system-volume-linux.js +160 -0
  20. package/dist/alarms/system-volume-ownership.js +76 -8
  21. package/dist/alarms/system-volume.js +44 -23
  22. package/dist/cli/arguments.js +212 -0
  23. package/dist/cli/completion.js +44 -0
  24. package/dist/cli/doctor.js +156 -0
  25. package/dist/cli/interactive.js +79 -0
  26. package/dist/cli/listener.js +227 -0
  27. package/dist/cli/output.js +121 -0
  28. package/dist/cli/render-tui.js +34 -0
  29. package/dist/cli.js +178 -199
  30. package/dist/platform/capabilities.js +8 -1
  31. package/dist/platform/desktop-media.js +61 -0
  32. package/dist/platform/diagnostics.js +273 -0
  33. package/dist/platform/json-worker.js +111 -0
  34. package/dist/platform/launch-command.js +9 -6
  35. package/dist/platform/mpris.js +356 -0
  36. package/dist/platform/network.js +69 -1
  37. package/dist/platform/omarchy.js +147 -0
  38. package/dist/platform/packages.js +7 -1
  39. package/dist/platform/runtime.js +1 -1
  40. package/dist/platform/terminals.js +24 -4
  41. package/dist/player/airplay-discovery.js +144 -61
  42. package/dist/player/airplay-policy.js +15 -0
  43. package/dist/player/airplay-process.js +63 -0
  44. package/dist/player/airplay-readiness.js +42 -0
  45. package/dist/player/airplay-sender-health.js +49 -49
  46. package/dist/player/airplay-sender-package.js +5 -0
  47. package/dist/player/airplay-sender-patch.js +102 -4
  48. package/dist/player/airplay-setup.js +51 -0
  49. package/dist/player/airplay-worker.js +97 -41
  50. package/dist/player/backend-install.js +9 -6
  51. package/dist/player/ffmpeg-input.js +37 -0
  52. package/dist/player/mpv-desktop-media.js +194 -0
  53. package/dist/player/mpv-ipc-client.js +51 -2
  54. package/dist/player/player-controller.js +390 -73
  55. package/dist/player/radio-engine.js +282 -0
  56. package/dist/playlists/playlist.js +18 -16
  57. package/dist/providers/cache.js +291 -75
  58. package/dist/providers/discovery-session.js +111 -0
  59. package/dist/providers/provider-manager.js +106 -28
  60. package/dist/providers/radio-browser.js +272 -41
  61. package/dist/providers/radio-garden.js +4 -2
  62. package/dist/setup-playback.js +152 -0
  63. package/dist/setup.js +88 -21
  64. package/dist/storage/file-lock.js +113 -0
  65. package/dist/storage/read-settings.js +33 -0
  66. package/dist/storage/replace-file.js +20 -0
  67. package/dist/storage/repository.js +247 -0
  68. package/dist/storage/station-identity.js +21 -0
  69. package/dist/storage/station-schema.js +27 -0
  70. package/dist/storage/store.js +249 -76
  71. package/dist/ui/AdaptiveContent.js +18 -10
  72. package/dist/ui/App.js +708 -454
  73. package/dist/ui/AppContent.js +5 -5
  74. package/dist/ui/airplay-settings.js +12 -5
  75. package/dist/ui/bidi-ranges.js +45 -0
  76. package/dist/ui/components/AdaptiveMarquee.js +16 -9
  77. package/dist/ui/format.js +37 -4
  78. package/dist/ui/help-content.js +5 -2
  79. package/dist/ui/rtl-output.js +137 -0
  80. package/dist/ui/screen-items.js +10 -4
  81. package/dist/ui/screens/AirPlaySettingsScreen.js +3 -3
  82. package/dist/ui/screens/AlarmsScreen.js +5 -2
  83. package/dist/ui/screens/HelpScreen.js +3 -3
  84. package/dist/ui/screens/SettingsScreen.js +16 -16
  85. package/dist/ui/screens/StatsScreen.js +1 -1
  86. package/dist/ui/text-direction.js +9 -0
  87. package/dist/ui/use-alarm-tui.js +24 -24
  88. package/dist/ui/use-app-input.js +42 -8
  89. package/dist/ui/use-command-executor.js +21 -14
  90. package/dist/ui/visualizers/gallop.js +1 -1
  91. package/dist/ui/visualizers/receiver-style-registry.js +2 -1
  92. package/dist/update-check.js +2 -1
  93. package/docs/THIRD_PARTY_NOTICES.md +6 -4
  94. package/package.json +34 -11
  95. package/scripts/build-airplay-native.mjs +22 -0
  96. package/vendor/node-airtunes2/LICENSE +208 -0
  97. package/vendor/node-airtunes2/RADIOCLI_PATCH.md +29 -0
  98. package/vendor/node-airtunes2/README.md +225 -0
  99. package/vendor/node-airtunes2/UPSTREAM.json +50 -0
  100. package/vendor/node-airtunes2/binding.gyp +41 -0
  101. package/vendor/node-airtunes2/lib/ap2_test.js +4 -0
  102. package/vendor/node-airtunes2/lib/atv.js +307 -0
  103. package/vendor/node-airtunes2/lib/atvAuthenticator.js +136 -0
  104. package/vendor/node-airtunes2/lib/audio_out.js +69 -0
  105. package/vendor/node-airtunes2/lib/circular_buffer.js +133 -0
  106. package/vendor/node-airtunes2/lib/config.js +26 -0
  107. package/vendor/node-airtunes2/lib/device_airtunes.js +532 -0
  108. package/vendor/node-airtunes2/lib/devices.js +266 -0
  109. package/vendor/node-airtunes2/lib/ed25519.js +26 -0
  110. package/vendor/node-airtunes2/lib/homekit/credentials.js +86 -0
  111. package/vendor/node-airtunes2/lib/homekit/encryption.js +69 -0
  112. package/vendor/node-airtunes2/lib/homekit/number.js +44 -0
  113. package/vendor/node-airtunes2/lib/homekit/tlv.js +95 -0
  114. package/vendor/node-airtunes2/lib/http.js +189 -0
  115. package/vendor/node-airtunes2/lib/index.d.ts +141 -0
  116. package/vendor/node-airtunes2/lib/index.js +127 -0
  117. package/vendor/node-airtunes2/lib/ntp.js +37 -0
  118. package/vendor/node-airtunes2/lib/num_util.js +21 -0
  119. package/vendor/node-airtunes2/lib/packet_pool.js +43 -0
  120. package/vendor/node-airtunes2/lib/rtsp.js +1807 -0
  121. package/vendor/node-airtunes2/lib/srp.js +158 -0
  122. package/vendor/node-airtunes2/lib/udp_servers.js +214 -0
  123. package/vendor/node-airtunes2/lib/util.js +12 -0
  124. package/vendor/node-airtunes2/package.json +31 -0
  125. package/vendor/node-airtunes2/src/CADebugMacros.h +257 -0
  126. package/vendor/node-airtunes2/src/CAHostTimeBase.cpp +105 -0
  127. package/vendor/node-airtunes2/src/CAHostTimeBase.h +224 -0
  128. package/vendor/node-airtunes2/src/aes_utils.c +864 -0
  129. package/vendor/node-airtunes2/src/aes_utils.h +24 -0
  130. package/vendor/node-airtunes2/src/base64.c +136 -0
  131. package/vendor/node-airtunes2/src/base64.h +42 -0
  132. package/vendor/node-airtunes2/src/bindings.cc +29 -0
  133. package/vendor/node-airtunes2/src/codec.cc +170 -0
  134. package/vendor/node-airtunes2/src/coreaudio.cc +332 -0
@@ -0,0 +1,24 @@
1
+ #ifndef _AES_H
2
+ #define _AES_H
3
+
4
+ #ifndef uint8
5
+ #define uint8 unsigned char
6
+ #endif
7
+
8
+ #ifndef uint32
9
+ #define uint32 unsigned long int
10
+ #endif
11
+
12
+ typedef struct
13
+ {
14
+ uint32 erk[64]; /* encryption round keys */
15
+ uint32 drk[64]; /* decryption round keys */
16
+ int nr; /* number of rounds */
17
+ }
18
+ aes_context;
19
+
20
+ int aes_set_key( aes_context *ctx, uint8 *key, int nbits );
21
+ void aes_encrypt( aes_context *ctx, uint8 input[16], uint8 output[16] );
22
+ void aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] );
23
+
24
+ #endif /* aes.h */
@@ -0,0 +1,136 @@
1
+ /*
2
+ * Copyright (c) 1995-2001 Kungliga Tekniska H�gskolan
3
+ * (Royal Institute of Technology, Stockholm, Sweden).
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ *
17
+ * 3. Neither the name of the Institute nor the names of its contributors
18
+ * may be used to endorse or promote products derived from this software
19
+ * without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31
+ * SUCH DAMAGE.
32
+ */
33
+
34
+ #ifdef HAVE_CONFIG_H
35
+ #include <config.h>
36
+ RCSID("$Id: base64.c,v 1.1.1.1 2005/07/23 13:57:04 shiro Exp $");
37
+ #endif
38
+ #include <stdlib.h>
39
+ #include <string.h>
40
+ #include "base64.h"
41
+
42
+ static char base64_chars[] =
43
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
44
+
45
+ static int
46
+ pos(char c)
47
+ {
48
+ char *p;
49
+ for (p = base64_chars; *p; p++)
50
+ if (*p == c)
51
+ return p - base64_chars;
52
+ return -1;
53
+ }
54
+
55
+ int
56
+ base64_encode(const void *data, int size, char **str)
57
+ {
58
+ char *s, *p;
59
+ int i;
60
+ int c;
61
+ const unsigned char *q;
62
+
63
+ p = s = (char *) malloc(size * 4 / 3 + 4);
64
+ if (p == NULL)
65
+ return -1;
66
+ q = (const unsigned char *) data;
67
+ i = 0;
68
+ for (i = 0; i < size;) {
69
+ c = q[i++];
70
+ c *= 256;
71
+ if (i < size)
72
+ c += q[i];
73
+ i++;
74
+ c *= 256;
75
+ if (i < size)
76
+ c += q[i];
77
+ i++;
78
+ p[0] = base64_chars[(c & 0x00fc0000) >> 18];
79
+ p[1] = base64_chars[(c & 0x0003f000) >> 12];
80
+ p[2] = base64_chars[(c & 0x00000fc0) >> 6];
81
+ p[3] = base64_chars[(c & 0x0000003f) >> 0];
82
+ if (i > size)
83
+ p[3] = '=';
84
+ if (i > size + 1)
85
+ p[2] = '=';
86
+ p += 4;
87
+ }
88
+ *p = 0;
89
+ *str = s;
90
+ return strlen(s);
91
+ }
92
+
93
+ #define DECODE_ERROR 0xffffffff
94
+
95
+ static unsigned int
96
+ token_decode(const char *token)
97
+ {
98
+ int i;
99
+ unsigned int val = 0;
100
+ int marker = 0;
101
+ if (strlen(token) < 4)
102
+ return DECODE_ERROR;
103
+ for (i = 0; i < 4; i++) {
104
+ val *= 64;
105
+ if (token[i] == '=')
106
+ marker++;
107
+ else if (marker > 0)
108
+ return DECODE_ERROR;
109
+ else
110
+ val += pos(token[i]);
111
+ }
112
+ if (marker > 2)
113
+ return DECODE_ERROR;
114
+ return (marker << 24) | val;
115
+ }
116
+
117
+ int
118
+ base64_decode(const char *str, void *data)
119
+ {
120
+ const char *p;
121
+ unsigned char *q;
122
+
123
+ q = (unsigned char*)data;
124
+ for (p = str; *p && (*p == '=' || strchr(base64_chars, *p)); p += 4) {
125
+ unsigned int val = token_decode(p);
126
+ unsigned int marker = (val >> 24) & 0xff;
127
+ if (val == DECODE_ERROR)
128
+ return -1;
129
+ *q++ = (val >> 16) & 0xff;
130
+ if (marker < 2)
131
+ *q++ = (val >> 8) & 0xff;
132
+ if (marker < 1)
133
+ *q++ = val & 0xff;
134
+ }
135
+ return q - (unsigned char *) data;
136
+ }
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska H�gskolan
3
+ * (Royal Institute of Technology, Stockholm, Sweden).
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ *
17
+ * 3. Neither the name of the Institute nor the names of its contributors
18
+ * may be used to endorse or promote products derived from this software
19
+ * without specific prior written permission.
20
+ *
21
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31
+ * SUCH DAMAGE.
32
+ */
33
+
34
+ /* $Id: base64.h,v 1.1.1.1 2005/07/23 13:57:04 shiro Exp $ */
35
+
36
+ #ifndef _BASE64_H_
37
+ #define _BASE64_H_
38
+
39
+ int base64_encode(const void *data, int size, char **str);
40
+ int base64_decode(const char *str, void *data);
41
+
42
+ #endif
@@ -0,0 +1,29 @@
1
+ #include <v8.h>
2
+ #include <node.h>
3
+
4
+
5
+ using namespace v8;
6
+ using namespace node;
7
+
8
+
9
+ namespace nodeairtunes {
10
+
11
+ void InitCodec(Local<Object>);
12
+ #ifdef __APPLE__
13
+ void InitCoreAudio(Local<Object>);
14
+ #endif
15
+
16
+ void Initialize(Local<Object> target) {
17
+
18
+ Isolate* isolate = v8::Isolate::GetCurrent();
19
+ HandleScope scope(isolate);
20
+
21
+ InitCodec(target);
22
+ #ifdef __APPLE__
23
+ InitCoreAudio(target);
24
+ #endif
25
+ }
26
+
27
+ } // nodeairtunes namespace
28
+
29
+ NODE_MODULE(airtunes, nodeairtunes::Initialize);
@@ -0,0 +1,170 @@
1
+ #include <node.h>
2
+ #include <node_buffer.h>
3
+ #include <v8.h>
4
+ #include <cstring>
5
+
6
+ extern "C" {
7
+ #include "aes_utils.h"
8
+ }
9
+
10
+ #include "base64.h"
11
+
12
+
13
+ using namespace v8;
14
+ using namespace node;
15
+
16
+ const int kBlockSize = 16;
17
+ static int kFramesPerPacket = 352;
18
+
19
+ // These values should be changed at each iteration
20
+ static uint8_t iv [] = { 0x78, 0xf4, 0x41, 0x2c, 0x8d, 0x17, 0x37, 0x90, 0x2b, 0x15, 0xa6, 0xb3, 0xee, 0x77, 0x0d, 0x67 };
21
+ static uint8_t aes_key [] = { 0x14, 0x49, 0x7d, 0xcc, 0x98, 0xe1, 0x37, 0xa8, 0x55, 0xc1, 0x45, 0x5a, 0x6b, 0xc0, 0xc9, 0x79 };
22
+
23
+ namespace nodeairtunes {
24
+
25
+
26
+ void EncodeALAC(const FunctionCallbackInfo<Value>& args) {
27
+ Isolate* isolate = Isolate::GetCurrent();
28
+ Local<Context> ctx = isolate->GetCurrentContext();
29
+ EscapableHandleScope scope(isolate);
30
+
31
+ if(args.Length() < 4) {
32
+ printf("expected: EncodeALAC(encoder, pcmData, pcmSize, alacData, alacSize)\n");
33
+ args.GetReturnValue().Set(Null(isolate));
34
+ }
35
+
36
+ // Local<Object> wrapper;
37
+ // args[0]->ToObject(ctx).ToLocal(&wrapper);
38
+ // ALACEncoder *encoder = (ALACEncoder*)wrapper->GetAlignedPointerFromInternalField(0);
39
+
40
+ Local<Value> pcmBuffer = args[1];
41
+ Local<Object> pcmObj;
42
+ pcmBuffer->ToObject(ctx).ToLocal(&pcmObj);
43
+ unsigned char* pcmData = (unsigned char*)Buffer::Data(pcmObj);
44
+
45
+ Local<Value> alacBuffer = args[2];
46
+ Local<Object> alacObj;
47
+ alacBuffer->ToObject(ctx).ToLocal(&alacObj);
48
+ unsigned char* alacData = (unsigned char*)Buffer::Data(alacObj);
49
+
50
+ int32_t pcmSize = args[3]->Int32Value(ctx).FromJust();
51
+
52
+ // AudioFormatDescription inputFormat, outputFormat;
53
+ // FillInputAudioFormat(&inputFormat);
54
+ // FillOutputAudioFormat(&outputFormat);
55
+
56
+ int32_t alacSize = pcmSize;
57
+
58
+ int bsize = 352;
59
+ int frames = 352;
60
+ int *size = &alacSize;
61
+ uint8_t *sample = pcmData;
62
+ uint8_t **out = &alacData;
63
+
64
+ #ifndef min
65
+ #define min(a,b) (((a) < (b)) ? (a) : (b))
66
+ #endif
67
+
68
+ uint8_t *p;
69
+ uint32_t *in = (uint32_t*) sample;
70
+ int count;
71
+
72
+ frames = min(frames, bsize);
73
+
74
+ // *out = (uint8_t*) malloc(bsize * 4 + 8);
75
+ p = *out;
76
+
77
+ *p++ = (1 << 5);
78
+ *p++ = 0;
79
+ *p++ = (1 << 4) | (1 << 1) | ((bsize & 0x80000000) >> 31); // b31
80
+ *p++ = ((bsize & 0x7f800000) << 1) >> 24; // b30--b23
81
+ *p++ = ((bsize & 0x007f8000) << 1) >> 16; // b22--b15
82
+ *p++ = ((bsize & 0x00007f80) << 1) >> 8; // b14--b7
83
+ *p = ((bsize & 0x0000007f) << 1); // b6--b0
84
+ *p++ |= (*in & 0x00008000) >> 15; // LB1 b7
85
+
86
+ count = frames - 1;
87
+
88
+ while (count--) {
89
+ // LB1 b6--b0 + LB0 b7
90
+ *p++ = ((*in & 0x00007f80) >> 7);
91
+ // LB0 b6--b0 + RB1 b7
92
+ *p++ = ((*in & 0x0000007f) << 1) | ((*in & 0x80000000) >> 31);
93
+ // RB1 b6--b0 + RB0 b7
94
+ *p++ = ((*in & 0x7f800000) >> 23);
95
+ // RB0 b6--b0 + next LB1 b7
96
+ *p++ = ((*in & 0x007f0000) >> 15) | ((*(in + 1) & 0x00008000) >> 15);
97
+
98
+ in++;
99
+ }
100
+
101
+ // last sample
102
+ // LB1 b6--b0 + LB0 b7
103
+ *p++ = ((*in & 0x00007f80) >> 7);
104
+ // LB0 b6--b0 + RB1 b7
105
+ *p++ = ((*in & 0x0000007f) << 1) | ((*in & 0x80000000) >> 31);
106
+ // RB1 b6--b0 + RB0 b7
107
+ *p++ = ((*in & 0x7f800000) >> 23);
108
+ // RB0 b6--b0 + next LB1 b7
109
+ *p++ = ((*in & 0x007f0000) >> 15);
110
+
111
+ // when readable size is less than bsize, fill 0 at the bottom
112
+ count = (bsize - frames) * 4;
113
+ while (count--) *p++ = 0;
114
+
115
+ // frame footer ??
116
+ *(p-1) |= 1;
117
+ *p = (7 >> 1) << 6;
118
+
119
+ *size = p - *out + 1;
120
+ //encoder->Encode(inputFormat, outputFormat, pcmData, alacData, &alacSize);
121
+
122
+ args.GetReturnValue().Set(Integer::New(isolate, alacSize));
123
+ }
124
+
125
+ void EncryptAES(const FunctionCallbackInfo<Value>& args) {
126
+ Isolate* isolate = v8::Isolate::GetCurrent();
127
+ Local<Context> ctx = isolate->GetCurrentContext();
128
+ EscapableHandleScope scope(isolate);
129
+
130
+ if(args.Length() < 2) {
131
+ printf("expected: EncryptAES(alacData, alacSize)\n");
132
+ args.GetReturnValue().Set(Null(isolate));
133
+ }
134
+
135
+ Local<Value> alacBuffer = args[0];
136
+ Local<Object> alacObj;
137
+ alacBuffer->ToObject(ctx).ToLocal(&alacObj);
138
+ unsigned char* alacData = (unsigned char*)Buffer::Data(alacObj);
139
+ int32_t alacSize = args[1]->Int32Value(isolate->GetCurrentContext()).FromJust();
140
+
141
+ // This will encrypt data in-place
142
+ uint8_t *buf;
143
+ int i = 0, j;
144
+ uint8_t nv[kBlockSize];
145
+
146
+ aes_context aes_ctx;
147
+ aes_set_key(&aes_ctx, aes_key, 128);
148
+ memcpy(nv, iv, kBlockSize);
149
+
150
+ while(i + kBlockSize <= alacSize) {
151
+ buf = alacData + i;
152
+
153
+ for(j = 0; j < kBlockSize; j++)
154
+ buf[j] ^= nv[j];
155
+
156
+ aes_encrypt(&aes_ctx, buf, buf);
157
+ memcpy(nv, buf, kBlockSize);
158
+
159
+ i += kBlockSize;
160
+ }
161
+
162
+ args.GetReturnValue().Set(Null(isolate));
163
+ }
164
+
165
+ void InitCodec(Local<Object> target) {
166
+ NODE_SET_METHOD(target, "encodeALAC", EncodeALAC);
167
+ NODE_SET_METHOD(target, "encryptAES", EncryptAES);
168
+ }
169
+
170
+ } // nodeairtunes namespace