mtproto 0.0.29 → 0.0.31
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.
- checksums.yaml +4 -4
- data/ext/factorization/factorization.c +57 -23
- data/lib/mtproto/client/api/export_bot_token.rb +14 -0
- data/lib/mtproto/client/api/send_message.rb +3 -2
- data/lib/mtproto/client/api.rb +1 -0
- data/lib/mtproto/tl/objects/updates_difference.rb +10 -4
- data/lib/mtproto/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7dc46e6630ceabe739c317ee739b3b23a62e60fec9164fcce46549570c2ae440
|
|
4
|
+
data.tar.gz: 99cfdf36c0bb6101dd1d5389ec28c81616c02ec5303ba3200cfa6caa960fe77d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8bbbf72972ce201874a7980453d776d7de4b99aa34918eb6ddee300c35cdbacda900b9a2ecf4a34faf916666fc8c98e0194e8830c58300804d98be5e5eedef27
|
|
7
|
+
data.tar.gz: 314835babb0a97abc5e3f75bf0f7b231d08b91c8b32d5862985f70e33edf89e39663c48bf84c74c9931e5675989f00e7b1cb2edb3a48878690afe4e790dbd4d3
|
|
@@ -1,11 +1,46 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
2
|
#include <stdint.h>
|
|
3
|
-
#include <math.h>
|
|
4
3
|
|
|
5
4
|
static VALUE mMTProto;
|
|
6
5
|
static VALUE mCrypto;
|
|
7
6
|
static VALUE mFactorization;
|
|
8
7
|
|
|
8
|
+
static uint64_t
|
|
9
|
+
mulmod(uint64_t a, uint64_t b, uint64_t m)
|
|
10
|
+
{
|
|
11
|
+
return (uint64_t)(((__uint128_t)a * b) % m);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static uint64_t
|
|
15
|
+
gcd64(uint64_t a, uint64_t b)
|
|
16
|
+
{
|
|
17
|
+
while (b) {
|
|
18
|
+
uint64_t t = a % b;
|
|
19
|
+
a = b;
|
|
20
|
+
b = t;
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Pollard's rho with f(x) = x^2 + c (mod n). Returns a non-trivial factor, or n
|
|
26
|
+
* on failure (cycle with no factor) so the caller can retry with another c. The
|
|
27
|
+
* MTProto pq is a product of two ~31-bit primes, so this finds a factor in a
|
|
28
|
+
* few thousand steps rather than the ~2^31 of trial division. */
|
|
29
|
+
static uint64_t
|
|
30
|
+
pollard_rho(uint64_t n, uint64_t c)
|
|
31
|
+
{
|
|
32
|
+
uint64_t x = 2, y = 2, d = 1;
|
|
33
|
+
while (d == 1) {
|
|
34
|
+
x = (mulmod(x, x, n) + c) % n;
|
|
35
|
+
y = (mulmod(y, y, n) + c) % n;
|
|
36
|
+
y = (mulmod(y, y, n) + c) % n;
|
|
37
|
+
uint64_t diff = x > y ? x - y : y - x;
|
|
38
|
+
if (diff == 0) return n;
|
|
39
|
+
d = gcd64(diff, n);
|
|
40
|
+
}
|
|
41
|
+
return d;
|
|
42
|
+
}
|
|
43
|
+
|
|
9
44
|
static VALUE
|
|
10
45
|
factorize_pq(VALUE self, VALUE pq_bytes)
|
|
11
46
|
{
|
|
@@ -23,33 +58,32 @@ factorize_pq(VALUE self, VALUE pq_bytes)
|
|
|
23
58
|
rb_raise(rb_eArgError, "Number must be > 3");
|
|
24
59
|
}
|
|
25
60
|
|
|
61
|
+
uint64_t p;
|
|
26
62
|
if (n % 2 == 0) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
63
|
+
p = 2;
|
|
64
|
+
} else {
|
|
65
|
+
uint64_t d = n;
|
|
66
|
+
for (uint64_t c = 1; c < 256; c++) {
|
|
67
|
+
d = pollard_rho(n, c);
|
|
68
|
+
if (d != n && d > 1) break;
|
|
69
|
+
}
|
|
70
|
+
if (d == n || d <= 1) {
|
|
71
|
+
rb_raise(rb_eRuntimeError, "No non-trivial factors found (n might be prime)");
|
|
72
|
+
}
|
|
73
|
+
p = d;
|
|
31
74
|
}
|
|
32
75
|
|
|
33
|
-
uint64_t
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (p > q) {
|
|
40
|
-
uint64_t tmp = p;
|
|
41
|
-
p = q;
|
|
42
|
-
q = tmp;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
VALUE result = rb_ary_new2(2);
|
|
46
|
-
rb_ary_push(result, ULL2NUM(p));
|
|
47
|
-
rb_ary_push(result, ULL2NUM(q));
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
76
|
+
uint64_t q = n / p;
|
|
77
|
+
if (p > q) {
|
|
78
|
+
uint64_t tmp = p;
|
|
79
|
+
p = q;
|
|
80
|
+
q = tmp;
|
|
50
81
|
}
|
|
51
82
|
|
|
52
|
-
|
|
83
|
+
VALUE result = rb_ary_new2(2);
|
|
84
|
+
rb_ary_push(result, ULL2NUM(p));
|
|
85
|
+
rb_ary_push(result, ULL2NUM(q));
|
|
86
|
+
return result;
|
|
53
87
|
}
|
|
54
88
|
|
|
55
89
|
void Init_factorization(void)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../../tl/objects/export_bot_token'
|
|
4
|
+
require_relative '../../tl/objects/exported_bot_token'
|
|
5
|
+
|
|
6
|
+
module MTProto
|
|
7
|
+
class Client
|
|
8
|
+
class API
|
|
9
|
+
def export_bot_token(bot:, revoke: false)
|
|
10
|
+
rpc_call(TL::ExportBotToken.new(bot: bot, revoke: revoke), TL::ExportedBotToken).body.token
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -17,12 +17,13 @@ module MTProto
|
|
|
17
17
|
# A `reply_to` (with optional `quote_text`/`quote_offset`) replies to a message,
|
|
18
18
|
# optionally pinning the quoted fragment.
|
|
19
19
|
def send_message(peer:, message: '', random_id: nil, reply_to: nil, entities: nil,
|
|
20
|
-
parse_mode: nil, rich_markdown: nil, quote_text: nil, quote_offset: nil, no_webpage: false
|
|
20
|
+
parse_mode: nil, rich_markdown: nil, quote_text: nil, quote_offset: nil, no_webpage: false,
|
|
21
|
+
reply_markup: nil)
|
|
21
22
|
message, entities = Markdown.parse(message) if parse_mode && entities.nil? && rich_markdown.nil?
|
|
22
23
|
rpc_call(
|
|
23
24
|
TL::SendMessage.new(peer: peer, message: message, random_id: random_id, reply_to: reply_to,
|
|
24
25
|
entities: entities, rich_markdown: rich_markdown, quote_text: quote_text, quote_offset: quote_offset,
|
|
25
|
-
no_webpage: no_webpage),
|
|
26
|
+
no_webpage: no_webpage, reply_markup: reply_markup),
|
|
26
27
|
TL::UpdateShortSentMessage
|
|
27
28
|
).body
|
|
28
29
|
end
|
data/lib/mtproto/client/api.rb
CHANGED
|
@@ -18,6 +18,7 @@ require_relative 'api/get_bot_callback_answer'
|
|
|
18
18
|
require_relative 'api/send_message'
|
|
19
19
|
require_relative 'api/set_typing'
|
|
20
20
|
require_relative 'api/get_contacts'
|
|
21
|
+
require_relative 'api/export_bot_token'
|
|
21
22
|
require_relative 'api/pin_message'
|
|
22
23
|
require_relative 'api/unpin_all_messages'
|
|
23
24
|
require_relative 'api/get_pinned_messages'
|
|
@@ -8,12 +8,12 @@ require_relative 'updates'
|
|
|
8
8
|
module MTProto
|
|
9
9
|
module TL
|
|
10
10
|
class UpdatesDifference
|
|
11
|
-
attr_reader :type, :date, :seq, :new_messages, :pts, :state, :chats, :users, :guest_queries
|
|
11
|
+
attr_reader :type, :date, :seq, :new_messages, :pts, :state, :chats, :users, :guest_queries, :managed_bots
|
|
12
12
|
|
|
13
13
|
SCHEMA_PATH = File.expand_path('../../../../data/tl-schema.json', __dir__)
|
|
14
14
|
|
|
15
15
|
def initialize(type:, date: nil, seq: nil, new_messages: [], pts: nil, state: nil, chats: [], users: [],
|
|
16
|
-
guest_queries: [])
|
|
16
|
+
guest_queries: [], managed_bots: [])
|
|
17
17
|
@type = type
|
|
18
18
|
@date = date
|
|
19
19
|
@seq = seq
|
|
@@ -23,6 +23,7 @@ module MTProto
|
|
|
23
23
|
@chats = chats
|
|
24
24
|
@users = users
|
|
25
25
|
@guest_queries = guest_queries
|
|
26
|
+
@managed_bots = managed_bots
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
def self.schema
|
|
@@ -47,6 +48,7 @@ module MTProto
|
|
|
47
48
|
|
|
48
49
|
UPDATE_NEW_MESSAGE = 0x1f2b0afd
|
|
49
50
|
UPDATE_NEW_CHANNEL_MESSAGE = 0x62ba04d9
|
|
51
|
+
UPDATE_MANAGED_BOT = 0x4880ed9a
|
|
50
52
|
|
|
51
53
|
class << self
|
|
52
54
|
private
|
|
@@ -68,7 +70,7 @@ module MTProto
|
|
|
68
70
|
|
|
69
71
|
messages, offset = parse_messages_vector(data, offset)
|
|
70
72
|
offset = schema.skip_vector(data, offset) # new_encrypted_messages
|
|
71
|
-
other_messages, guest_queries, offset = parse_other_updates(data, offset)
|
|
73
|
+
other_messages, guest_queries, managed_bots, offset = parse_other_updates(data, offset)
|
|
72
74
|
chats, offset = Dialogs.chats_at(data, offset)
|
|
73
75
|
users, offset = Dialogs.users_at(data, offset)
|
|
74
76
|
state = UpdatesState.deserialize(data[offset..])
|
|
@@ -77,6 +79,7 @@ module MTProto
|
|
|
77
79
|
type: constructor == Constructors::UPDATES_DIFFERENCE ? :difference : :slice,
|
|
78
80
|
new_messages: messages + other_messages,
|
|
79
81
|
guest_queries: guest_queries,
|
|
82
|
+
managed_bots: managed_bots,
|
|
80
83
|
chats: chats, users: users, state: state
|
|
81
84
|
)
|
|
82
85
|
end
|
|
@@ -91,6 +94,7 @@ module MTProto
|
|
|
91
94
|
|
|
92
95
|
messages = []
|
|
93
96
|
guest_queries = []
|
|
97
|
+
managed_bots = []
|
|
94
98
|
count.times do
|
|
95
99
|
ctor = data[offset, 4].unpack1('L<')
|
|
96
100
|
if [UPDATE_NEW_MESSAGE, UPDATE_NEW_CHANNEL_MESSAGE].include?(ctor)
|
|
@@ -99,10 +103,12 @@ module MTProto
|
|
|
99
103
|
messages << msg.to_h if msg
|
|
100
104
|
elsif ctor == Updates::UPDATE_BOT_GUEST_CHAT_QUERY
|
|
101
105
|
guest_queries << Updates.extract_guest_query(data, offset)
|
|
106
|
+
elsif ctor == UPDATE_MANAGED_BOT
|
|
107
|
+
managed_bots << { user_id: data[offset + 4, 8].unpack1('Q<'), bot_id: data[offset + 12, 8].unpack1('Q<') }
|
|
102
108
|
end
|
|
103
109
|
offset = schema.skip(data, offset)
|
|
104
110
|
end
|
|
105
|
-
[messages, guest_queries, offset]
|
|
111
|
+
[messages, guest_queries, managed_bots, offset]
|
|
106
112
|
end
|
|
107
113
|
|
|
108
114
|
def parse_messages_vector(data, offset)
|
data/lib/mtproto/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mtproto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.31
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Artem Levenkov
|
|
@@ -65,6 +65,7 @@ files:
|
|
|
65
65
|
- lib/mtproto/client/api.rb
|
|
66
66
|
- lib/mtproto/client/api/check_password.rb
|
|
67
67
|
- lib/mtproto/client/api/export_authorization.rb
|
|
68
|
+
- lib/mtproto/client/api/export_bot_token.rb
|
|
68
69
|
- lib/mtproto/client/api/export_login_token.rb
|
|
69
70
|
- lib/mtproto/client/api/get_bot_callback_answer.rb
|
|
70
71
|
- lib/mtproto/client/api/get_channel_difference.rb
|