• 0 Posts
  • 6 Comments
Joined 1 year ago
cake
Cake day: June 17th, 2023

help-circle



  • Circular dependencies can be removed in almost every case by splitting out a large module into smaller ones and adding an interface or two.

    In your bot example, you have a circular dependency where (for example) the bot needs to read messages, then run a command from a module, which then needs to send messages back.

        v-----------\
      bot    command_foo
        \-----------^
    

    This can be solved by making a command conform to an interface, and shifting the responsibility of registering commands to the code that creates the bot instance.

        main <---
        ^        \
        |          \
        bot ---> command_foo
    

    The bot module would expose the Bot class and a Command instance. The command_foo module would import Bot and export a class implementing Command.

    The main function would import Bot and CommandFoo, and create an instance of the bot with CommandFoo registered:

    // bot module
    export interface Command {
        onRegister(bot: Bot, command: string);
        onCommand(user: User, message: string);
    }
    
    // command_foo module
    import {Bot, Command} from "bot";
    export class CommandFoo implements Command {
        private bot: Bot;
    
        onRegister(bot: Bot, command: string) {
            this.bot = bot;
        }
    
        onCommand(user: User, message: string) {
            this.bot.replyTo(user, "Bar.");
        }
    }
    
    // main
    import {Bot} from "bot";
    import {CommandFoo} from "command_foo";
    
    let bot = new Bot();
    bot.registerCommand("/foo", new CommandFoo());
    bot.start();
    

    It’s a few more lines of code, but it has no circular dependencies, reduced coupling, and more flexibility. It’s easier to write unit tests for, and users are free to extend it with whatever commands they want, without needing to modify the bot module to add them.


  • I glossed through some of the specifications, and it appears to be voluntary. In a way, it’s similar to signing git commits: you create an image and chose to give provenance to (sign) it. If someone else edits the image, they can choose to keep the record going by signing the change with their identity. Different images can also be combined, and that would be noted down and signed as well.

    So, suppose I see some image that claims to be an advertisement for “the world’s cheapest car”, a literal rectangle of sheet metal and wooden wheels. I could then inspect the image to try and figure out if that’s a legitimate product by BestCars Ltd, or if someone was trolling/memeing. It turns out that the image was signed by LegitimateAdCompany, Inc and combined signed assets from BestCars, Ltd and StockPhotos, LLC. Seeing that all of those are legitimate businesses, the chain of provenance isn’t broken, and BestCars being known to work with LegitimateAdCompany, I can be fairly confident that it’s not a meme photo.

    Now, with that being said…

    It doesn’t preclude scummy camera or phone manufacturers from generating identities unique their customers and/or hardware and signing photos without the user’s consent. Thankfully, at least, it seems like you can just strip away all the provenance data by copy-pasting the raw pixel data into a new image using a program that doesn’t support it (Paint?).

    All bets are off if you publish or upload the photo first, though—a perceptual hash lookup could just link the image back to original one that does contain provenance data.


  • “Impede the replacement of” and “compatible battery” has a lot of room for interpretation. I hope they’re defined explicitly somewhere, or else we’re going to find implementations that effectively restrict non-OEM batteries while still adhering to the letter of the law.

    For example, all batteries lacking a cryptographically-verified “certification” handshake could have safety restrictions such as:

    • Limited maximum amperage draw, achieved by under-clocking the SoC and sleeping performance cores.

    • Lower thermal limits while charging the device, meaning fast charging may be limited or preemptively disabled to ensure that the battery does not exceed an upper threshold of you-might-want-to-put-it-in-the-fridge degrees.

    • Disabling wireless charging capabilities, just in case magnetic induction affects the uncertified battery full of unknown and officially-untested components.

    • A pop-up warning the user every time the device is plugged into or unplugged from a charger.

    All of that would technically meet the condition insofar that it’s neither impeding the physical replacement nor rendering the device inoperable, but it would still effectively make the phone useless unless you pay for a (possibly-overpriced) OEM part.

    If they explicitly defined “Impede the replacement of” as “prevent replacement of or significantly alter user experience as a result of replacing,” and “compatible battery” as “electrically-compatible battery” all those cases would be covered.

    Might be a bit of cynical take, but I don’t have too much faith in the spirit of the law being adhered to when profits are part of the equation.